本页内容

QQuickWidget 与 QQuickView 对比示例

演示了QQuickWidget 相较于作为本机窗口嵌入的QQuickView 所具备的优势。

带有红色叠加层的 Qt 徽标,用于演示控件堆叠效果

该示例展示了如何在基于QWidget 的用户界面中,通过两种不同的方法显示相同的Qt Quick 场景:

点击Show widget overlay 复选框可演示一种小部件堆叠情况:在嵌入原生窗口时,其渲染效果与预期不符,而使用QQuickWidget 则可使其按预期渲染。

运行示例

您可以通过以下方式运行示例:

平台注意事项

即使嵌入到QQuickWidget 中,Qt Quick 场景仍使用直接的 OpenGL 渲染。这证实了渲染过程仍继续使用加速的 3D API。

因此,该示例与 OpenGL 紧密关联,无法在 Vulkan、Metal 或 Direct3D 等其他图形 API 上运行。

多采样抗锯齿

您可以通过勾选相应的复选框来启用多采样抗锯齿。启用后,QQuickWidget 会将内容渲染到多采样渲染缓冲区中。每次渲染通过后,内容会被解析为标准的 2D 纹理。这使得Qt Quick 内容能够启用抗锯齿,同时不会影响基于QWidget 的其余用户界面。

如果您使用的是QQuickView ,原生窗口会为其表面请求多采样。根据平台的支持情况,这将提供类似的效果。

键盘输入

Qt Quick 场景支持用户交互,包括文本输入,无论使用何种嵌入技术。使用QQuickWidget 时,输入事件会自动转发至Qt Quick 场景。

示例项目 @ code.qt.io

另请参阅 Qt Quick 控件。

© 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.