In my application, the user may change the properties of the OpenGL format (i.e. double buffering, multisampling, depth of various buffers, ...).
For now, there is only one QGLWidget in my application, and if the user changes anything, I destroy and recreate the widget.
Now, I would like to have more than one widget. So if the format change, I need to destroy/recreate all the widgets. As the widget can assume various configurations, it destroying/recreating them is difficult. So is there a way to change the format of a QGLWidget at runtime?
Alternatively, is there a way to replace a widget by another one? (i.e. destroy a widget and place a new one exactly where it use to stand)
This may work:
QGLFormat newFormat;
newFormat.setDoubleBuffer(true);
// ...
theGLWidget->context().setFormat(newFormat);
Edit: You can also call QGLWidget::setFormat
directly, but it's obsolete and may not always work. I think it's safer to recreate the widget. Here's how: Put your GL widget in a sublayout (any kind - e.g. QVBoxLayout) that contains nothing but your GL widget. When you want to replace it with a new GL widget, delete the old one, and insert your new widget in that sublayout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With