Qt Quick 控件
Qt Quick 控件模块是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,需要链接到该模块库,可以是直接链接,也可以通过其他依赖项间接链接。包括CMake和qmake 在内的多种构建工具都为此提供了专门的支持。
使用 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 Qt Widgets 可通过The Qt Company 提供的商业许可证使用。此外,它还提供自由软件许可证。自 Qt 5.4 起,这些自由软件许可证包括GNU 较少通用公共许可证第 3 版或 GNU 通用公共许可证第 2 版。更多详情请参阅Qt 许可协议。
© 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.