Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can QWindow replace QGLWidget?

Tags:

qt

opengl

qt5

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?

like image 734
Alexander Theißen Avatar asked Aug 01 '13 00:08

Alexander Theißen


1 Answers

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

like image 191
PeterT Avatar answered Nov 13 '22 15:11

PeterT