1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\page qtquickcontrols-changes-qt6.html
\title Changes to Qt Quick Controls
\ingroup changes-qt-5-to-6
\brief 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.
\section1 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
\l{Qt 5.15: Qt Quick Controls vs Qt Quick Controls 1} topic in the Qt 5
documentation.
\section1 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.
\section2 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 \c 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:
\code
module MyStyle
Button 1.0 Button.qml
\endcode
\omit
TODO: Once we have documentation for the CMake function qt6_add_qml_module,
this would be a good place to link to it, stating that you don't have to
manually write the qmldir files.
\endomit
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:
\list
\li QQuickStyle::addStylePath()
\li QQuickStyle::availableStyles()
\li QQuickStyle::path()
\li QQuickStyle::stylePathList()
\li QT_QUICK_CONTROLS_STYLE_PATH
\endlist
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.
\section3 Style names
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:
\badcode
MyProject
├── main.qml
├── HomePage.qml
└── +material
└───HomePage.qml
\endcode
In Qt 6, \c +material becomes \c +Material:
\badcode
MyProject
├── main.qml
├── HomePage.qml
└── +Material
└───HomePage.qml
\endcode
All of the existing ways to \l {Using Styles in Qt Quick Controls}{run an
application with a specific style} are still supported.
\section2 Runtime and compile time style selection
Importing a style now has extra meaning due to the way that imports work
internally. Previously, importing \c QtQuick.Controls would register the
control types from the current style with the QML engine:
\qml
import QtQuick.Controls
\endqml
We refer to this as runtime style selection, as the style is selected at
runtime.
Explicitly importing \c QtQuick.Controls.Material would then simply expose
any extra API provided by that style (for example, the attached Material
type):
\qml
import QtQuick.Controls.Material
\endqml
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 \c main.qml:
\qml
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Controls.Universal
ApplicationWindow {
width: 600
height: 400
visible: true
Material.theme: darkMode ? Material.Dark : Material.Light
Universal.theme: darkMode ? Universal.Dark : Universal.Light
// Child items, etc.
}
\endqml
You can move the common code into a "base" component:
\qml
// MainWindow.qml
import QtQuick.Controls
ApplicationWindow {}
\endqml
Then, add a \c +Material subdirectory, and in it, add the Material-specific code into \c MainWindow.qml:
\qml
// +Material/MainWindow.qml
import QtQuick.Controls.Material
ApplicationWindow {
Material.theme: darkMode ? Material.Dark : Material.Light
}
\endqml
Do the same for Universal:
\qml
// +Universal/MainWindow.qml
import QtQuick.Controls.Universal
ApplicationWindow {
Universal.theme: darkMode ? Universal.Dark : Universal.Light
}
\endqml
Then, in \c main.qml:
\qml
import QtQuick.Controls
MainWindow {
width: 600
height: 400
visible: true
// Child items, etc.
}
\endqml
See also: \l {Using File Selectors with Qt Quick Controls}.
\section1 Default Style
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:
\list
\li Android: \l {Material Style}
\li Linux: \l {Fusion Style}
\li macOS: \macos Style
\li Windows: Windows Style
\li All other platforms: \l {Basic Style}
\endlist
\section1 Palette
The palette API was moved to QQuickItem. The various APIs that use palettes
in Qt Quick Controls are unchanged.
\section1 Controls
\section2 ApplicationWindow
The deprecated overlay properties and attached API were removed. Use the
\l Overlay attached type instead.
\section2 ComboBox
The \l {ComboBox::}{pressed} property is now read-only. To modify the
visual pressed state of a ComboBox, use the \l {ComboBox::}{down} property
instead.
\section2 Container
The deprecated \c removeItem(var) function was removed.
\l {Container::}{removeItem(Item)} or \l {Container::}{takeItem(int)} can
be used instead.
\section2 Dialog
\l {Dialog}'s \l {Dialog::}{accepted()} and \l {Dialog::}{rejected()}
signals are now emitted before \l {Popup::}{closed()} when calling
\l {Dialog::}{done()}, \l {Dialog::}{accept()} and \l {Dialog::}{reject()}.
\section2 Menu
The deprecated \c removeItem(var) function was removed.
\l {Menu::}{removeItem(Item)} or \l {Menu::}{takeItem(int)} can be used
instead.
\section2 ToolTip
\l {ToolTip}'s timeout now begins only after \l {Popup::}{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.
\section2 StackView
The StackView.Transition enum value was deprecated. The operation argument
can be omitted in order to use the default transition for any given
operation.
\section2 Tumbler
\l {Item::}{implicitWidth} and \l {Item::}{implicitHeight} must now be
provided for \l {Tumbler}'s \l {Control::}{contentItem}, making it
consistent with all other controls.
*/
|