The Qt Quick Widgets module is a convenience wrapper for
QQuickWindow
. It will automatically load and display a QML scene when given the URL of the main
qml
file. Alternatively, you can instantiate QML objects using
QQmlComponent
and place them in a manually set-up
QQuickWidget
.
典型用法:
QQuickWidget *view = new QQuickWidget; view->setSource(QUrl::fromLocalFile("myqmlfile.qml")); view->show();
QQuickWidget also manages resizing the view and the root item. By default, the resizeMode 被设为 SizeViewToRootObject , which will load the component and resize it to fit the view. Alternatively, you can set resizeMode to SizeViewToRootObject , which will resize the view to the root item.
使用 Qt 模块的 C++ API 要求直接 (或透过其它依赖) 链接到模块库。几个构建工具对此有专用支持,包括 CMake and qmake .
使用
find_package()
命令定位所需模块组件在
Qt6
包:
find_package(Qt6 REQUIRED COMPONENTS QuickWidgets)
target_link_libraries(mytarget PRIVATE Qt6::QuickWidgets)
更多细节,见 构建采用 CMake 概述。
要配置采用 qmake 构建模块,添加模块作为值为
QT
变量在工程的 .pro 文件:
QT += quickwidgets
Qt Quick Widget is available under commercial licenses from Qt 公司 。此外,它在自由软件许可下也是可用的。从 Qt 5.4 起,这些自由软件许可是 GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 了解更多细节。