QQuickWidget - QQuickView比较示例
展示了QQuickWidget 与嵌入为本地窗口的QQuickView 相比的优势。

该示例允许使用两种不同的方法在基于QWidget 的用户界面中显示相同的Qt Quick 场景:
- 使用QQuickView 。
它作为子窗口使用,并与QWidget::createWindowContainer()
- 使用QQuickWidget 。
点击Show widget overlay 复选框演示了嵌入本地窗口时无法按预期渲染的部件堆叠情况,而QQuickWidget 则使其按预期渲染。
运行示例
要运行来自 Qt Creator,打开Welcome 模式,然后从Examples 中选择示例。更多信息,请参阅Qt Creator: 教程:构建并运行。
平台说明
Qt Quick 场景使用直接 OpenGL 渲染,即使嵌入QQuickWidget 时也是如此。这证明渲染继续使用加速 3D API。
因此,该示例与 OpenGL 绑定,无法与其他图形 API(如 Vulkan、Metal 或 Direct3D)配合使用。
多采样抗锯齿
您可以通过选择相应的复选框启用多采样抗锯齿。启用后,QQuickWidget 会将内容渲染到多采样渲染缓冲区中。每次渲染通过后,内容都会解析为标准的 2D 纹理。这样就可以对Qt Quick 内容进行抗锯齿处理,而不会影响基于QWidget 的用户界面的其他部分。
如果您使用的是QQuickView ,本机窗口会请求对其表面进行多重采样。根据平台支持情况,这也会产生类似的结果。
键盘输入
无论使用何种嵌入技术,Qt Quick 场景都支持用户交互,包括文本输入。使用QQuickWidget 时,输入事件会自动转发到Qt Quick 场景。
另请参阅 Qt Quick Widgets。
© 2026 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.