Alexander Theißen
Alexander Theißen

Reputation: 3889

How can QWindow replace QGLWidget?

QT docs say that since qt5 you should use the QOpenGL* classes instead of QGL*.

Problem is there is no QGLWidget replacement. I figured out that instead you should use QWindow in conjunction with QOpenGLContext and a call to setSurfaceType( OpenGLSurface );.

Only problem is that a QWindow can't have QWidget as parent. So how can I embed a QWindow aka. my OpenGL drawing surface into other widgets?

Upvotes: 17

Views: 8584

Answers (1)

PeterT
PeterT

Reputation: 8284

QT 5.1 is in a weird situation OpenGL and QWidget (and derived) wise. There's no QGLWidget replacement yet all other QGL classes have clear replacements.

If you don't want to use the old QGLWidget you indeed have to manufacture yourself a replacement with QWindow. So, first you set up your QWindow then, as you correctly said call setSurfaceType( OpenGLSurface ); before you call create(); on it. Then you create a new QOpenGLContext and use its makeCurrent() function and pass your QWindow. Then you create a QWidget from the QWindow using QWidget::createWindowContainer(window);

But this is only a temporary hack, that you shouldn't have to use unless you actually want to mix QtQuick an QWidget. You can then replace this temporary hack with the actual replacement in 5.2.0 5.4.0 called QOpenGLWidget

Upvotes: 15

Related Questions