Black screen with QOpenGLWidget while docking
-
Environment:
QOpenGLWidget inside a QWidget, added to a QStackedWidget, inside a QDockWidget
Qt 6.10.0 WindowsProblem:
I have a file browser widget (QDockWidget) that lazily creates a QOpenGLWidget-based 3D viewer when the user opens a file. The widget is added to a QStackedWidget via addWidget() and made current.
It displays correctly and everything works fine, but when the QWidget is docked the OpenGL window becomes black. After undocking it is normal again.
If you dock QWidget (before starting opengl scene) and then start it everything works fine.
Also if you open the file for the first time:
a) when floating QWidget flashes (disappears and appears again)
b) when its docked the whole main window flashesAlso the screen is black but if I press the settings button (I can't see) the menu shows normally and I see it
Already tried the AA_ShareOpenGLContexts, delaying repainting.
-
I'm experiencing a similar issue. When the first OpenGLWidget is added to my DockWidget, it flashes—that is, it quickly alternates between hidden and visible. However, this only happens with the first OpenGLWidget. If I add another one, the problem doesn't occur. Do you have any suggestions?
-
Same thing here. I managed to get rid of the black screen by initializing it earlier (I was using lazy initialization). However, the flash still appears, and as you can see, it happens only the first time it starts.
Maybe creating it at the start of the program and then hiding it could be a workaround.
-
Same thing here. I managed to get rid of the black screen by initializing it earlier (I was using lazy initialization). However, the flash still appears, and as you can see, it happens only the first time it starts.
Maybe creating it at the start of the program and then hiding it could be a workaround.
@aabb2137 said in Black screen with QOpenGLWidget while docking:
Maybe creating it at the start of the program and then hiding it could be a workaround.
//Mainwindow constr auto *dummyGL = new QOpenGLWidget(this); dummyGL->show(); dummyGL->hide();This solved my flashing problem, but is it correct solution ?
-
The flashing happens because of
"Note: When dynamically adding a QOpenGLWidget into a widget hierarchy, e.g. by parenting a new QOpenGLWidget to a widget where the corresponding top-level widget is already shown on screen, the associated native window may get implicitly destroyed and recreated if the QOpenGLWidget is the first of its kind within its window. This is because the window type changes from RasterSurface to OpenGLSurface and that has platform-specific implications. This behavior is new in Qt 6.4."
as stated in https://doc.qt.io/qt-6/qopenglwidget.html#limitations-and-other-considerations.If you create a tiny invisible dummy QOpenGLWidget and parent it before the widget is embedded into the main window, it should work seamlessly.