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.
Using a Qt module's C++ API requires linking against the module library, either directly or through other dependencies. Several build tools have dedicated support for this, including CMake and qmake .
使用
find_package()
command to locate the needed module component in the
Qt6
包:
find_package(Qt6 REQUIRED COMPONENTS QuickWidgets)
target_link_libraries(mytarget PRIVATE Qt6::QuickWidgets)
更多细节,见 构建采用 CMake 概述。
To configure the module for building with qmake, add the module as a value of the
QT
variable in the project's .pro file:
QT += quickwidgets
Qt Quick Widget is available under commercial licenses from Qt 公司 。此外,它在自由软件许可下也是可用的。从 Qt 5.4 起,这些自由软件许可是 GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 了解更多细节。