Changes to Qt Quick Controls¶
Migrate Qt Quick Controls to Qt 6.
Qt 6 is a result of the conscious effort to make the framework more efficient and easy to use.
We try to maintain compatibility for all the public APIs in each release. Some changes were inevitable in an effort to make Qt a better framework.
In this topic we summarize those changes in Qt Quick Controls, and provide guidance to handle them.
Migrating from Qt Quick Controls 1¶
Qt Quick Controls 1 was deprecated in Qt 5.11 and is removed from Qt 6.0. Use Qt Quick Controls (previously known as Qt Quick Controls 2) instead. For more information, refer to the Qt 5.15: Qt Quick Controls vs Qt Quick Controls 1 topic in the Qt 5 documentation.
Type registration changes¶
Qt Quick Controls has undergone some large, mostly internal changes in Qt 6. By making use of the improved type registration introduced in Qt 5.15, we pave the way for compilation of the module’s QML files to C++ and enable tooling to become more effective. In particular, Qt Creator’s QML code model should have a more complete picture of types, making its completion and error checking of Qt Quick Controls code more reliable. Static analysis tools like qmllint and qmlformat also benefit by becoming aware of the types that are now declared at compile time in C++.
As a result of these changes, some things are done a little differently.
Custom styles are now proper QML modules¶
To enable compile time type registration, each Qt Quick Controls style is now a proper QML module. Previously, a single
Button.qml was sufficient to create your own style. While convenient, this required some non-standard API, which in turn required adaptation in tooling like Qt Designer.
Now, all QML types that a style implements must be declared in that style’s qmldir file:
module MyStyle Button 1.0 Button.qml
By unifying this with the rest of the QML world, styles become more familiar to developers and hopefully easier to understand for beginners. As a consequence, the following API had to be removed:
Now that the styles are required to be found in the QML engine’s import path like any other QML module, it is no longer necessary or possible to support this API.
In addition, there is now only one valid, case-sensitive form for style names: “Material”, “MyStyle”, and so on. That is: the style name must exactly match the name of the QML module. This also applies to file selectors, where previously, all style names were lower case. For example, where the following was a valid structure for a Qt 5 project:
MyProject ├── main.qml ├── HomePage.qml └── +material └───HomePage.qml
In Qt 6,
MyProject ├── main.qml ├── HomePage.qml └── +Material └───HomePage.qml
All of the existing ways to run an application with a specific style are still supported.
Runtime and compile time style selection¶
Importing a style now has extra meaning due to the way that imports work internally. Previously, importing
QtQuick.Controls would register the control types from the current style with the QML engine:
We refer to this as runtime style selection, as the style is selected at runtime.
QtQuick.Controls.Material would then simply expose any extra API provided by that style (for example, the attached Material type):
Now, explicitly importing a style does both.
This effectively means that the control types (like Button) from the last imported style will be used. We refer to this as compile time style selection.
This has implications for existing code. Namely, if your application supports more than one style, move these imports into their own QML files that are file-selected.
For example, if you have the following
You can move the common code into a “base” component:
Then, add a
+Material subdirectory, and in it, add the Material-specific code into
Do the same for Universal:
See also: Using File Selectors with Qt Quick Controls .
The Default style was renamed to “Basic”, as it is no longer the default style. Instead, the default style is now chosen based on the platform that Qt was built for:
Therefore, applications that didn’t specify a style in Qt 5 and have customized controls should explicitly specify the Basic style in Qt 6 to ensure that those controls look and behave as they did with Qt 5.
The palette API was moved to
QQuickItem . The various APIs that use palettes in Qt Quick Controls are unchanged.
The deprecated overlay properties and attached API were removed. Use the Overlay attached type instead.
removeItem(var) function was removed.
takeItem(int) can be used instead.
rejected() signals are now emitted before
closed() when calling
ToolTip ‘s timeout now begins only after
opened() has been emitted. This results in tooltips with enter transitions being visible for the entire duration of the timeout property. This means that they are visible slightly longer than they were before, so it may be worthwhile to visually check tooltips in your application and adjust timeouts if necessary.
The StackView .Transition enum value was deprecated. The operation argument can be omitted in order to use the default transition for any given operation.
© 2022 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.