0

I am looking for some example code that I can use to save an image of my Qt application. The application is a QMainWindow that contains a QGLWidget. I want to be able to screen capture all the GUIs (including the QGLWidget rendering) but have not been able to find any example code for this.

What I've tried: QPixmap pixmap = QPixMap::grabWidget(QApplication::activeWindow); pixmap.save(QString("test.png"));

This only save the GUIs but leaves a black background around the QGLWidget.

Anyone know of a technique for doing this in Qt 4.8.4?

Thanks,

  • [This answer](https://forum.qt.io/topic/45541/capture-widget-with-opengl-content/2) from the Qt forums recomends that you do a two-step capture (one for the QMainWindow and one for the QGLWidget) – Felipe Lema Aug 27 '15 at 11:57
  • Yes, I was able to capture both images. The QPixmap contains the GUI screenshot and the QImage contains the QGLWidget screen grab. However, I don't know how to properly set the mask so that I can combine the two. Are there example code on how to do this? – Hien Nguyen Aug 27 '15 at 15:04
  • You can use [positioning](http://stackoverflow.com/questions/4450595/qt-determine-absolute-widget-and-cursor-position) with [`geometry(...)`](http://doc.qt.io/qt-4.8/qwidget.html#geometry-prop). You'll probably have to take some helper function, but this should help you. – Felipe Lema Aug 27 '15 at 19:50

0 Answers0