[Qt-interest] Overlay in conflict to QPainter?

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Thu Jul 22 16:53:06 CEST 2010


unimd at web.de wrote on Thursday, July 22, 2010 11:12 AM:

> ...
> Has anyone used this function so far? Or do you have any suggestions
> to my problem? Everything will help. 

I studied quickly the "overpainting" example annotations: http://doc.trolltech.com/4.6/opengl-overpainting.html

I am pretty sure you read them already as well, since it makes some important notes about when to initialise the GL matrices, when to paint with the QPainter, for instance:

- To cooperate fully with QPainter, we defer matrix stack operations and attribute initialization until the widget needs to be updated.
  (in other words: no GL matrix stack initialisation in initializeGL()!)

- In this example, we implement paintEvent() rather than paintGL() to render our scene. When drawing on a QGLWidget, the paint engine used by QPainter  performs certain operations that change the states of the OpenGL implementation's matrix and property stacks. Therefore, it is necessary to make all the OpenGL calls to display the 3D graphics before we construct a QPainter to draw the 2D overlay.

Also the GL matrix stack is re-created each time when a frame has to be rendered. ("This is unnecessary in OpenGL examples that implement the paintGL() function because the matrix stacks are usually unmodified between calls to resizeGL() and paintGL().") But apparently when drawing with QPainter that changes the GL matrix stack. Also, the GL state is stored and restored before and after the GL calls.

The "Summary" at the bottom of above URL wraps it all up.

But that the above probably (only) applies to the "pre-beginNativePainting()" (Qt 4.6) world. Since Qt 4.6 the information is probably a bit outdated (since I guess with beginNativePainting() you can paint at /any/ time, even between GL paint calls, and the GL matrix stack storing/restoring is probably done implicitly by begin/endNativePainting?).

All that said, I still don't know whether that works within a call to paintOverlayGL()! As it appears using a QPainter within a QGLWidget is only possible when being called from a paintEvent() method.

If this is the case then what you could do is to implement a "software" overlay:

Within paintEvent():

- when the GL scene changes, render (update) it into a (GL) "pixmap"

- GL painting: draw the GL pixmap (cheap)

- Qt painting: draw the "overlay" with the QPainter


Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list