take a snapshop of a qgraphicsview
-
18-09-2019 - |
Question
I am using Qt 4.5 and a qgraphicsscene/view to show video to the user. I would like to provide a "take a snapshop" button and I am sure that there is a pretty straightforward way much simpler of everything I am thinking about. How can I do this elegantly?
BTW, the code is here : http://gitorious.org/handy
Solution
You can use the method QWidget::grab()
. This method renders the given widget to a pixmap and returns that pixmap. Then you can do whatever you like with that, like saving to a file using QPixmap::save()
.
OTHER TIPS
See QScreen::grabWindow()
and QWidget::grab()
.
With grabWindow
you can even capture a window outside of your application, e.g. the screenshot example program:
http://doc.qt.io/qt-5/qtwidgets-desktop-screenshot-example.html