[Interest] Issue with QGLWidget inside QMdiArea

Thomas Robitaille thomas.robitaille at gmail.com
Thu Jan 21 13:25:02 CET 2016


Hi everyone,

I am trying to add a QGLWidget in an application I am working on.
However, I'm running into an issue which is that if I try and add the
QGLWidget to a QMdiArea, there is a very noticeable spatial lag
between where the Qt window is drawn and the OpenGL canvas when
dragging the MDI sub-window around. In fact, the Qt window seems to
drag behind the OpenGL canvas.

Here's a short screencast demonstrating this problem, slowed down by a
factor of 10:

https://www.youtube.com/watch?v=k7T7Sev91c8

The code I'm using to produce this is included below (in C++ with Qt4)
and can also be found here:

https://github.com/astrofrog/qt-build-sandbox/blob/master/opengl/opengl_mdi.cpp

This issue does NOT happen if I don't use a QMdiArea. Does anyone know
what might be causing this problem, and how to fix it? Is it a bug in
Qt?

Thanks in advance for any help!

Cheers,
Tom

---

#include <QApplication>
#include <QMenuBar>
#include <QMainWindow>
#include <QMdiArea>
#include <QGLWidget>
#include <QMdiSubWindow>

class PlainGLWidget : public QGLWidget
{
protected:
    virtual void paintGL();
};

void PlainGLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}


int main(int argc, char *argv[]) {

    QApplication app(argc, argv);

    QMainWindow *window = new QMainWindow;

    QMdiArea *mdi = new QMdiArea;
    window->setCentralWidget(mdi);

    PlainGLWidget *viewer = new PlainGLWidget;
    viewer->resize(600,600);

    QMdiSubWindow *sub = new QMdiSubWindow;
    sub->setWidget(viewer);
    mdi->addSubWindow(sub);
    sub->resize(600,600);

    window->show();
    window->raise();

    return app.exec();

}



More information about the Interest mailing list