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.
2 Answers
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.
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

- 812
- 6
- 19