How to change QGLFormat for an existing QGLWidget at runtime?

In my application, the user can change the properties of the OpenGL format (i.e. double buffering, multisampling, the depth of various buffers, etc.).

Currently, there is only one QGLWidget in my application, and if the user changes something, I destroy and recreate the widget.

Now I would like to have more than one widget. Therefore, if the format changes, I need to destroy / recreate all the widgets. Since the widget can take various configurations, it is difficult to destroy / recreate it. So, is there a way to change the QGLWidget format at runtime?

Alternatively, is there a way to replace the widget with another? (i.e. destroy the widget and place a new one where it will stand)

+6
c ++ user-interface dynamic qt4 opengl
source share
1 answer

This may work:

QGLFormat newFormat; newFormat.setDoubleBuffer(true); // ... theGLWidget->context().setFormat(newFormat); 

Edit: You can also directly call QGLWidget::setFormat , but obsolete may not always work . I think it’s safer to recreate the widget. Here's how: Put your GL widget in a subtask (any view, such as QVBoxLayout) that contains nothing but your GL widget. If you want to replace it with new GL widgets, delete the old one and insert a new widget into this sub-layer.

+4
source share

All Articles