Qt Quick 小工具示例
演示如何使用QQuickWidget 类将Qt Quick 与Qt Widgets 应用程序混合使用。

该示例演示了如何在Qt Widgets 应用程序中嵌入Qt Quick 场景,以及如何在Qt Widgets 和Qt Quick 之间整合不同的用户界面。其中包括
- Qt Widgets 和 之间的标签聚焦Qt Quick
- 在应用程序中嵌入QQuickView QLayout
运行示例
运行示例 Qt Creator,打开Welcome 模式并从Examples 中选择示例。更多信息,请参阅Qt Creator: 教程:构建和运行。
Qt Quick 视图集成
为演示Qt Quick 视图的无缝集成,示例采用了多种方法截取Qt Quick 视图的屏幕截图。
在主菜单中选择File ,然后选择以下任一选项,即可抓取Qt Quick 视图的截图:
- Grab framebuffer - 使用QQuickWidget::grabFramebuffer 函数抓取屏幕截图。
- Render to pixmap - 使用QWidget::render 函数和作为参数的QPixmap 实例抓取屏幕截图。这种方法常见于Qt Widgets 。
- Grab via grabToImage - 调用 QML 文件中声明的
performLayerBasedGrab函数。performLayerBasedGrab函数调用 QML Item 的Item::grabToImage 函数抓取屏幕截图。这种方法演示了如何从 C++ 调用嵌套视图的 QML API。

MDI 中的 QQuickWidget
该示例还演示了如何使用QQuickWidget 将硬件加速的Qt Quick 场景无缝集成到 Qt Widgets Multiple Document Interface (MDI) 应用程序中。
要打开一个新的 MDI 子窗口,请在主菜单中选择Window >Add tab widget 。

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