[Qt-interest] invalid drawable with Cocoa/QGLWidget
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Thu Feb 25 20:35:05 CET 2010
Alan Norton wrote on Thursday, February 25, 2010 7:47 PM:
> Thanks, Oliver.
> I have a bit more information. This problem seems to only occur if
> the qglwidget is not visible when it first gets a paintEvent(). In
> my example the qglwidget is scrolled out of view when its containing
> widget first is shown.
Okay, that is somewhat different than in my setup. In my case the QGLWidget is contained in a tab which is initially also not selected, when the main window is displayed. When I select the corresponding tab only then becomes my QGLWidget visible, but at this time it is fully visible.
I have quickly set breakpoints in initializeGL() and paintGL(): initializeGL() is only called the first time I click the tab which contains my QGLWidget (in other words: it is only initialised shortly before it is about to become visible).
As the Qt docs states, the QGLContext is made current before initializeGL() (and paintGL and resizeGL), which off course implies that the QGLContext has already been created at that point. I believe that in fact the QGLContext is already created at construction time of the QGLWidget, which in my case happens off course when the application is started and the main window (which contains the tab widget and QGLWidget) is created:
- Application is started
- Widgets are created, QGLContext is created
- Then at some later point...
- QGLWidget becomes visible the first time -> initializeGL()
- Followed by the first paintGL()
As can be seen here (I am using Windows right now, but the Mac code should look similar with respect to when glInit() is called):
// This is the Windows specific Qt code
void QGLWidget::resizeEvent(QResizeEvent *)
{
Q_D(QGLWidget);
if (!isValid())
return;
makeCurrent(); // <-- At this point QGLContext already exists (and is made "current")
if (!d->glcx->initialized()) // <-- Check whether this widget is already initialised ...
glInit(); // ... and if not, call glInit -> initializeGL()
resizeGL(width(), height());
if (d->olcx) {
makeOverlayCurrent();
resizeOverlayGL(width(), height());
}
}
So no, you can't influence when QGLContext is created: it is created (most probably) from within the c'tor of QGLWidget (or even passed as parameter), surely even before initializeGL(), which on its turn is called before the first paintGL().
And since my QGLWidget is fully visible when it gets its first paintGL() call, my situation certainly is different than your :/
I assume you have some kind of "container widget" set in the QScrollArea. Couldn't this "container widget" (QGLWidget would be a "child" thereof) control which subwidgets really need to be repainted, by evaluating the rect() of the QPaintEvent it receives? So it would only paint those subwidgets which are actually visible, and your QGLWidget would receive its first paint event only when it would become (partly) visible - would that help?
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list