How to create an in-application screen shot tool
-
I would like to have a tool in my application to capture snapshots like with for example GreenShot.
What I expect is to have an action that turns on this tool and with the mouse I can select a region that is found automatically. For example in a 2x2 viewport with images the option to select one of the views or all.
How could I do that? How would I be able to catch mouse events without having handlers in the viewport itself?
Regards,
Marcel
-
Hi,
It can be done using QFileDialog::getSaveFileName()
(For taking snapshot of your screen)Ex:
(....)
QString filename = QFileDialog::getSaveFileName(this, "Snapshot", ".png");filename = filename + ".png";
(....)you can use any of the format in place of .png
And use QPixmap for the data and saving the path.
-
You can use QRubberBand to drag a area for which you want.
TopLeft is the mouse press pos. MouseMove moves the bottom right corner of it and on mosue release you trigger your screen capture code.For this you capture the whole screen and just cut out the global rect of the QRubebrBand widget.
Also see "this example":http://qt-project.org/doc/qt-4.8/desktop-screenshot.html.
Or did i misunderstood something?
Or do you just want to capture widgets inside your application?If so it's even simplier:
use QApplication::widgetAt() and display for example a blinking border around it. On mousepress then use QPixmap::grabWidget()Edit: To filter mouse events you can install an event Filter on the QApplication itself.
@qApp->installEventFilter(...)@ -
FYI QPixmap::grabWidget() has been obsoleted in 5.4: Changes To Qt GUI