本页面

Qt Quick 小工具示例

演示如何使用QQuickWidget 类将Qt QuickQt Widgets 应用程序混合使用。

MDI 子窗口中的数字时钟和旋转矩形

该示例演示了如何在Qt Widgets 应用程序中嵌入Qt Quick 场景,以及如何在Qt WidgetsQt 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

带有多个标签子窗口的 MDI 窗口

示例项目 @ code.qt.io

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