QQuickRenderControl OpenGL 示例

演示如何将Qt Quick 场景渲染为纹理,然后由非基于 Quick 的 OpenGL 渲染器使用。

Qt Quick 场景由QQuickWindow 管理,在屏幕上不可见。相反,渲染以 OpenGL 纹理为目标,并通过QQuickRenderControl 进行控制。

立方体直接使用 OpenGL 渲染,使用 Qt XML Enablers(如QWindowQOpenGLContextQOpenGLShaderProgramQOpenGLFunctions )。立方体的纹理与Qt Quick 渲染传递输出的纹理一致。

此外,还演示了基本的输入事件转发。按住鼠标左键时,背景Rectangle 颜色会通过 QML 绑定发生改变。同样,按住键盘上的一个键也会改变颜色。这证明了从应用程序发送的 "假 "事件(根据屏幕QWindow 上的事件生成)在Qt Quick 场景中被转发和处理。

示例项目 @ code.qt.io

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.