You are not logged in.

Dear visitor, welcome to If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.


Friday, March 16th 2012, 1:11pm

QGLWidget crashes with QPainter in some OpenGL versions


I've subclassed QGLWidget and reimplemented the paintEvent() where I first draw some 3D stuff and then draw 2D on top using QPainter. Everything was going fine until I found out that this only works in some computers. In others, it either crashes when creating the QPainter object or it simply does not draw the 2D graphics.
I used QGLFormat:penGLVersionFlags() to know the openGL version supported by each computer and discovered that computers with support up to:
version 1.1: don't draw 2D
version 2.1: work fine
version 4.0: crash with QPainter

In my solution I created a dummy widget and all the others use it as a sharedWidget in order to share display lists. If I create my QGLWidgets without a shared widget, QPainter doesn't cause a crash, but of course that doesn't work for me because I need to share display lists.

I thought of a work around. I could draw the 3D, render it into a QPixmap and draw the 2D on the pixmap (which works always fine), but how can I call the QGLWidget's paintEvent without it being visible to the user? Because with this solution, a QLabel would be used to show the 3D graphics to the user, instead of the QGLWidget. I'm also affraid that this solution will be much slower than just drawing everything in the QGLWidget and showing it to the user.

If anyone has any ideas why this problem happens or how to draw 3D graphics in an hidden QGLWidget, please help me. I'm running out of ideas here. Thanks!

Best regards,