Qt and OpenGL using QGLWidget
I am planning on porting our 3D editor for our engine from a MFC sdi application to a Qt application. What i have done so far is very basic but i am having issues.
I have a QMainWindow with a few docking widgets. For the central widget i have subclassed QGLWidget and overridden the 3 methods initializeGL, resizeGL and painGL. What i'm doing so far in these methods is very basic :
/// One time initialization.
glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
/// Called when the widget is resized.
void SceneView::resizeGL(int w, int h)
// Setup viewport, projection etc.
glViewport(0, 0, (GLint)w, (GLint)h);
/// Called when the widget is redrawn.
The problem is when i resize the application or one of the docking window, there is flickering. If i remove docking windows, there is still eavy flickering. It's like the gl widget is not redrawing at the same time as the rest. If i replace the gl widget by a stadard widget like QTextEdit, there is no problem.
I am using Qt 5.1.1 OpenGL with VS2012 toolchain.
QGLWidget class is deprecated. If you are writing new code, you should use QOpenGL* set of classes instead (and Qt 5.2, where the GL stuff has seen lots of updates).
@sierdzio When you want to use whole window new QWindow with an OpenGL surface format is the way to go but I don't think there is a replacement for QGLWidget. Or is embedding QWindow with QWidget::createWindowContainer() the new recommendation for widget-based apps?
I don't know, sorry. I'm just repeating the general impression I get from following the dev mailing list, and posts on this forum made by ZapB, who is the maintainer of OpenGL stuff in Qt.
I will answer myself: "Introducing QWidget::createWindowContainer()":http://blog.qt.digia.com/blog/2013/02/19/introducing-qwidgetcreatewindowcontainer/
Looks like that's the way.
@lbolduc try to replace QGLWidget with QWindow and see if that fixes the problem.
Thanks for the answers.
@Chris Kawa : yes i have read this post and i have tried to make a QWindow derived widget and to wrap it with createWindowContainer. It works (3D rendering works) but it has the same problem as the QGLWidget i.e. it causes flickering when the application is resized or when a docking widget in the application is resized (or as soon as some part of the application like a menu gets over the gl widget).
I have also read an older post about native widgets and how Qt 4.4 was supposed to address this problem
"Your text to link here...":http://blog.qt.digia.com/blog/2007/08/09/qt-invaded-by-aliens-the-end-of-all-flicker/
Unfortunatly, it seems the problem isn't solve with OpenGL widgets. I know Qt 5.2 is supposed to have updates concerning OpenGL, is this problem supposed to be solved with Qt 5.2 ?
Hm, you might try another approach. Flickering is caused by rapid repaints while resizing. You can try to "pause" the painting in OpenGL area when the resizing starts and refresh only when it's done.
Yes, or it is caused by erasing the background when repainting. There are various flags to control this behavior like Qt::WA_OpaquePaintEvent. I have tried those flags but it didn't change anything. I have also tried setting autoFillBackground to false but it didn't change anything either.
Btw, is it possible for me to upload the source code of my little program, it might be easier for someone more experienced then me with Qt to see what the problem is.