How should applications with OpenGL viewports be setup in QT6?
-
Hello,
I am trying to create an application with an embedded openGL "viewport" to see levels from my game engine.I see there is a
QOpenGLWidget
class from a "Qt OpenGL Widgets" (openglwidgets
) module. However in the MSVC modules picker, it only gives "Qt OpenGL" (opengl
) as an available module.With the Qt OpenGL module added to the project, I can include
<QOpenGLWindow>
, but I can't include<QOpenGLWidget>
. Is there a way to embed this window into my application so that it's not a separate popup?Also, does the QT backend have to use the same graphics library as I use in a Qt OpenGL Widget/Window? If I want to use OpenGL 4 in my window, do I have to force QT to use OpenGL 4 as well?
Thanks for any help,
Alek -
The documentation properly states on what to add to qmake pro-files or CMakeLists.txt when you want to use this class.
-
@AlekM said:
However in the MSVC modules picker, it only gives "Qt OpenGL" (opengl) as an available module.
Yes, for some reason it's missing in the picker dialog, but you can just type it in manually in the property editor and it works fine.
Is there a way to embed this window into my application so that it's not a separate popup?
Yes. There's static QWidget::createWindowContainer for that. It creates a widget host for QWindow, but if you're using widgets it's easier to use
QOpenGLWidget
, as it handles all the events and has fewer issues with stacking order and focus handling.