Capture widget with OpenGL content

  • Hello, sorry to make a thread from a stackoverflow post but basically I have the exact same problem and I was wondering if I'm forced to use the same workaround

    I need to programmatically capture a screenshot of the application's main window, including some OpenGL widgets

    Now here's what I've tried so far:

    • QPixmap::grabWidget doesn't work for the subwindows that use shader programs, apparently because the redirection context does not seem to support the necessary OpenGL extensions. (The rendering code checks that the associated context supports the required extensions, and refuses to continue if not.)
    • QPixmap::grabWindow silently leaves all OpenGL contexts empty -- even those that use basic primitives only.
    • QGLWidget::grabFrameBuffer works, but captures only the OpenGL context of the specific subwindow, whereas I'd like to grab the whole application (essentially what Alt+PrtScr does in Windows).[/quote]

  • The easiest way I can see is using grabWindow() first, which leaves empty (black?) OpenGL area, and then use grabFrameBuffer() on the OpenGL context, and paste that into the previously grabbed image. Looks like 2 steps to me, probably fast and efficient enough (still better than 3rd post in the link above, suggesting to screenshot each widget separately...)

    Also, please note that the thread you linked refers to Qt OpenGL module from Qt 4.x. If you're using Qt 5 things might be different.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.