Qt Quick 小工具

Qt Quick Widgets 模块是QQuickWindow 的便捷包装器。当获得qml 主文件的 URL 时,它会自动加载并显示 QML 场景。另外,您也可以使用QQmlComponent 来实例化 QML 对象,并将它们放置在手动设置的QQuickWidget 中。

典型用法

QQuickWidget *view = new QQuickWidget;
view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
view->show();

QQuickWidget 还可管理视图和根项目的大小调整。默认情况下, 设置为 ,这将加载组件并调整其大小以适应视图。或者,也可以将 设置为 ,这样就可以根据根项目调整视图大小。resizeMode SizeViewToRootObject resizeMode SizeViewToRootObject

使用模块

使用 Qt 模块的 C++ API 需要直接或通过其他依赖项链接模块库。有几种构建工具为此提供了专门支持,包括CMakeqmake

使用 CMake 构建

使用find_package() 命令在Qt6 软件包中找到所需的模块组件:

find_package(Qt6 REQUIRED COMPONENTS QuickWidgets)
target_link_libraries(mytarget PRIVATE Qt6::QuickWidgets)

更多详情,请参阅使用 CMake 构建概述。

使用 qmake 构建 quickwidgets

要配置使用 qmake 构建的模块,请在项目的 .pro 文件中添加该模块作为QT 变量的值:

QT += quickwidgets

参考资料

许可与归属

Qt Quick Widget 由Qt Company 根据商业许可提供。此外,它还受自由软件许可证的保护。自 Qt 5.4 起,这些自由软件许可证为GNU Lesser General Public License 第 3 版GNU General Public License 第 2 版。更多详情,请参阅Qt 许可

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