4

Is it possible to capture the screen rendering of a QML Component and save it to an image file? I would like to drive a Component through several different states, and capture its visual appearance for documentation purposes, without having to do screen/window captures.

Paul Carlisle
  • 415
  • 1
  • 5
  • 11

2 Answers2

3

Yes, you could set up your state transitions to call QWidget::grab then save it to a file through QPixmap.

If you need an example of how to set up your code to call QWidget::grab take a look at this answer: How to take ScreenShot Qt/QML

It's important to replace QPixmap::grabWidget with QWidget::grab because QPixmap::grabWidget is now obsolete. Once you have the QPixmap from QWidget::grab follow the documentation in QPixmap to save to the format you'd like such as jpeg, png, gif.

Here are some links to the documentation to help you out.

QWidget::grab

QPixmap

QPixmap::save

Community
  • 1
  • 1
Matthew
  • 2,759
  • 18
  • 28
2

With Qt 5.4 it is now made easier with grabToImage - this method resides on all QQuickItem objects.

EDIT It's worth mentioning that the item you call grabToImage() on must be a child of a top-level Window item container

Larpon
  • 812
  • 6
  • 19