QWindow如何替换QGLWidget? [英] How can QWindow replace QGLWidget?

查看:141
本文介绍了QWindow如何替换QGLWidget?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QT文档说,从qt5开始,您应该使用QOpenGL *类而不是QGL *.

问题是没有QGLWidget替代品.我发现应该将QWindow与QOpenGLContext结合使用,并调用setSurfaceType(OpenGLSurface);.

唯一的问题是QWindow不能将QWidget作为父级.所以我怎么能嵌入QWindow呢.我的OpenGL绘图表面可以放到其他小部件中?

解决方案

QT 5.1在OpenGL和QWidget(并派生)方面很奇怪.没有QGLWidget替代品,但所有其他QGL类都有明显的替代品.

如果您不想使用旧的QGLWidget,则确实必须用QWindow替代.因此,首先,您要设置QWindow,然后如您所说正确地调用setSurfaceType( OpenGLSurface );,然后再在其上调用create();.然后,创建一个新的QOpenGLContext并使用其makeCurrent()函数并传递您的QWindow.然后,使用 QWidget::createWindowContainer(window);QWindow创建QWidget >

但这只是一个临时性的技巧,除非您确实想将QtQuick与QWidget混合使用,否则不必使用.然后,您可以在 5.2.0 5.4.0 称为 QOpenGLWidget

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?

解决方案

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

这篇关于QWindow如何替换QGLWidget?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆