Qt application screenshot from application

I am trying to capture a screenshot of my application in an application. This is a Qt based application. Does anyone know how to do this? Any suggestions are welcome.

Summary

+4
source share
3 answers

You can specify any QWidget (including your QMainWindow ) to display it off-screen: http://developer.qt.nokia.com/doc/qt-4.8/qwidget.html#render

Technically, this is not a screenshot, since it clearly displays the widget for this purpose, and does not capture what is visible on the screen. For any purpose, it does not matter.

If you have a GL widget, you can / should use grabFramebuffer () instead, which has the advantage of capturing what is visible on the screen.

+3
source

In this example, you can get the whole screen of widgets. You can attach this method to any keystroke or waveform, as you prefer, to take a consistent screen shot.

 MyClass::screenshot() { QWidget *w = QApplication::activeWindow(); if(w) { static int count = 0; QPixmap p = QPixmap::grabWidget(w); p.save(QString("/your/path/screenshot%1.png").arg(count)); count++; } } 
+2
source

QPixmap allows you to capture a window if you have an identifier. My links are for PyQt, but I'm sure you can make adjustments:

How to get QPixmap or QImage pixel RGB values ​​- Qt, PyQt

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qpixmap.html#grabWindow

+1
source

Source: https://habr.com/ru/post/1395126/


All Articles