It's now recommended to use QWindow for OpenGL drawing. Is it possible to add a widget to this window? If so, how? If not, how should I go about adding widgets to an OpenGL program using Qt5?
Asked
Active
Viewed 2,122 times
4
-
possible duplicate of [How to create a Qt form class from a custom window?](http://stackoverflow.com/questions/23929301/how-to-create-a-qt-form-class-from-a-custom-window) – Dmitry Sazonov May 29 '14 at 10:36
-
How should your final result look like? You could think of going the other way around -- embedding your GL window into a QWidget hierarchy by using `QWidget::createWindowContainer`. – peppe May 29 '14 at 10:54
-
@peppe The problem with QWidget::createWindowContainer is that it prevents me from calling methods from the window object that was passed in. It also makes it impossible to inherit from. – Ben May 29 '14 at 10:56
-
Why does it prevent such a thing?! Use the `QWidget *` it returns for its UI management (layouting, etc.); use the `YourWindow *` you pass to it for anything else (logic). – peppe May 29 '14 at 11:00
-
@peppe Any changes I make to the window object after creating the container seem to have no effect on the widget. – Ben May 29 '14 at 11:01
-
Can you please elaborate? – peppe May 29 '14 at 13:19
1 Answers
2
An application will typically use QWidget
or QQuickView
for its UI, and not QWindow
directly. QWindow
is more low level than QWidget
. If you want to use QWindow
directly, more work is needed to accomplish the job. You should manually do all drawing related things which is not easy.
However, if you really want a QWindow
/QGuiApplication
instead of QWidget
/QApplication
, you can use QBackingStore which is used by QWidget
, or SceneGraph
which is used by QQuick
in QWindow::exposeEvent()
.
You can see an example of a minimal QWindow
based application using QPainter
here.

Angie Quijano
- 4,167
- 3
- 25
- 30

Nejat
- 31,784
- 12
- 106
- 138