[Qt-interest] disappearing widgets in QGraphicsScene

Yifei Li yifli at mtu.edu
Tue Nov 10 16:09:50 CET 2009


Thank you.

Unfortunately, I'm using Qt 4.5.

However, I fixed the problem by switching the order I push attribute bits and matrices:

So, instead of:
glPushAttrib
glPushMatrix

I do:
glPushMatrix
glPushAttrib


Now I'm feeling that getting the whole thing work is so tricky :) 
So is there anyone who can explain to me how QGraphicsScene renders embeded widgets under the hood? I'm too lazy to dig into the source :)

Yifei

----- Original Message -----
From: "Samuel Rødal" <sroedal at trolltech.com>
To: "Yifei Li" <yifli at mtu.edu>
Cc: "qt-interest" <qt-interest at trolltech.com>
Sent: Tuesday, November 10, 2009 6:42:51 AM GMT -05:00 US/Canada Eastern
Subject: Re: [Qt-interest] disappearing widgets in QGraphicsScene

Yifei Li wrote:
> Hi,
> 
> I kinda fixed the problem by saving and then restoring modelview and projection matrices.
> 
> However, the problem still persists when I enable multiple viewports. I tried glPushAttrib/glPopAttrib, but that did not help.
> 
> Here is what I tried:
> 
> void drawBackground(QPainter*, const QRectF&)
> {
>    glClearColor(...)
>    glClear(...);          // clear depth and color buffer
> 
>    glPushAttrib(GL_ALL_ATTRIB_BITS);
>    glMatrixMode(GL_PROJECTION);
>    glPushMatrix();
>    glMatrixMode(GL_MODELVIEW);
>    glPushMatrix();
> 
>    // render stuff in the 1st viewport
>    ...
>    // render stuff in the 2nd viewport
>    ...
> 
>    glMatrixMode(GL_PROJECTION);
>    glPopMatrix();
>    glMatrixMode(GL_MODELVIEW);
>    glPopMatrix();
>    glPopAttrib();
> }
> 
> Please help me out. Thanks
> 
> Yifei

If you're using Qt 4.6 you can try surrounding the OpenGL code with 
painter->beginNativePainting() and painter->endNativePainting(). That 
should lead to better synchronization when intermixing QPainter and raw 
OpenGL code (even if you don't use the QPainter in drawBackground it's 
used by QGraphicsView).

--
Samuel




More information about the Qt-interest-old mailing list