Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtquickcontrols-styles.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qtquickcontrols-styles.html
6
\title Styling Qt Quick Controls
7
8
\section1 Available Styles
9
10
Qt Quick Controls comes with a selection of styles.
11
12
\section2 Basic Style
13
14
\image qtquickcontrols-basic.png
15
{Gallery of controls in Basic style}
16
17
The \l {Basic Style} is a simple and light-weight all-round style that offers
18
the maximum performance for Qt Quick Controls.
19
20
\section2 Fusion Style
21
22
\include style-screenshots.qdocinc {file} {Fusion} {fusion}
23
24
The \l {Fusion Style} is a platform-agnostic style that offers a desktop-oriented
25
look and feel for Qt Quick Controls.
26
27
\section2 Imagine Style
28
29
\image qtquickcontrols-imagine.png
30
{Gallery of controls in Imagine style}
31
32
The \l {Imagine Style} is based on image assets. The style comes with a default
33
set of images which can easily be changed by providing a directory
34
with images using a predefined naming convention.
35
36
\section2 macOS Style
37
38
\include style-screenshots.qdocinc {file} {macOS} {macos}
39
40
The \l {macOS Style} is a native-looking style for macOS.
41
\note this style is only available for applications running on macOS.
42
43
\section2 iOS Style
44
45
\include style-screenshots.qdocinc {file} {iOS} {ios}
46
47
The \l {iOS Style} is a native-looking style for iOS based on image assets.
48
\note this style is only available for applications running on iOS.
49
50
\section2 Material Style
51
52
\include style-screenshots.qdocinc {file} {Material} {material}
53
54
The \l {Material Style} offers an appealing design based on the
55
\l {https://www.google.com/design/spec/material-design/introduction.html}
56
{Google Material Design Guidelines}, but requires more system resources than
57
the Basic style.
58
59
\section2 Universal Style
60
61
\include style-screenshots.qdocinc {file} {Universal} {universal}
62
63
The \l {Universal Style} offers an appealing design based on the
64
Microsoft Universal Design Guidelines,
65
but requires more system resources than the Basic style.
66
67
\section2 Windows Style
68
69
\image qtquickcontrols-windows.png
70
{Gallery of controls in Windows style}
71
72
The \l {Windows Style} is a native-looking style for Windows.
73
\note this style is only available for applications running on Windows.
74
75
\section2 FluentWinUI3 Style
76
77
\include style-screenshots.qdocinc {file} {FluentWinUI3} {fluentwinui3}
78
79
The \l {FluentWinUI3 Style} is a modern, native-looking style designed for platforms
80
running Windows 11 and above, which follows the Fluent UI and the WinUI 3 design guidelines.
81
The FluentWinUI3 can be run on all supported platforms.
82
83
\section1 Using Styles in Qt Quick Controls
84
85
\section2 Default Styles
86
87
If no style is explicitly set, a default style will be used. The style that
88
is used depends on the operating system:
89
90
\list
91
\li Android: \l {Material Style}
92
\li iOS: \l {iOS Style}
93
\li Linux: \l {Fusion Style}
94
\li macOS: \l {macOS Style}
95
\li Windows: \l {Windows Style}
96
\endlist
97
98
For all other operating systems, the \l {Basic Style} is used.
99
100
\section2 Compile-Time Style Selection
101
102
Compile-time style selection is a way of specifying a style to use by
103
directly or indirectly importing it in QML. Since it is selected at compile
104
time, you cannot change the style at run time if you use compile-time style
105
selection.
106
107
The most convenient way to use comile-time style selection is to import the
108
\e{QtQuick.Controls.Native} style. \c{QtQuick.Controls.Native} in turn
109
imports the \l{Default Styles}{default style} for the target platform. If
110
you import \c{QtQuick.Controls.Native}, you should not import any specific
111
other styles, nor the (run-time selected) \c{QtQuick.Controls} module.
112
\c{QtQuick.Controls.Native} imports the platform-default style for you and
113
that style handles its fallback. You can't have more than one top-level
114
style at the same time. For example:
115
116
\qml
117
// Refrain from importing QtQuick.Controls or specific styles.
118
import QtQuick.Controls.Native
119
120
ApplicationWindow {
121
// ...
122
}
123
\endqml
124
125
However, you can also import one specific style at compile time,
126
disregarding the platform defaults. For example, to import the Material
127
style:
128
129
\qml
130
// The style must be imported before any other QtQuick.Controls imports
131
// in order for run-time style selection API like QQuickStyle::name() to
132
// work.
133
import QtQuick.Controls.Material
134
135
ApplicationWindow {
136
// ...
137
}
138
\endqml
139
140
Notice that \c {QtQuick.Controls} (which is responsible for run-time style
141
selection) is not imported. The fallback style is specified by the qmldir
142
of the style:
143
144
\badcode
145
module QtQuick.Controls.Material
146
# ...
147
import QtQuick.Controls.Basic auto
148
\endcode
149
150
The benefit of compile-time style selection is that the
151
\l {The QML script compiler}{QML compiler} knows which specific style
152
is in use and can generate C++ code for bindings.
153
154
Another benefit is that the \c {QtQuick.Controls} plugin is not used and
155
therefore does not need to be deployed with the application.
156
157
Explicit imports are also necessary if your application is built
158
\l {Static Builds}{statically}.
159
160
A disadvantage of compile-time style selection is that one executable
161
cannot support multiple styles, as each style requires its own.
162
163
See \l {Mixing Style Selection} for information about mixing
164
compile-time and run-time style selection.
165
166
\section2 Run-Time Style Selection
167
168
Run-time style selection is a way of specifying a style to use by importing
169
\c QtQuick.Controls:
170
171
\qml
172
import QtQuick.Controls
173
\endqml
174
175
The \c{QtQuick.Controls} plugin will import the style that was set at runtime
176
via one of the following approaches:
177
178
\list
179
\li \l[CPP]{QQuickStyle::setStyle()}
180
\li The \c -style command line argument
181
\li The \l {Supported Environment Variables in Qt Quick Controls}
182
{QT_QUICK_CONTROLS_STYLE environment variable}
183
\li The \l {Qt Quick Controls Configuration File}{qtquickcontrols2.conf
184
configuration file}
185
\endlist
186
187
The priority of these approaches follows the order they are listed,
188
from highest to lowest. That is, using \c QQuickStyle to set the style will
189
always take priority over using the command line argument, for example.
190
191
Similarly, the fallback style can be set via one of the following methods:
192
\list
193
\li \l[CPP]{QQuickStyle::setFallbackStyle()}
194
\li The \l {Supported Environment Variables in Qt Quick Controls}
195
{QT_QUICK_CONTROLS_FALLBACK_STYLE environment variable}
196
\li The \l {Qt Quick Controls Configuration File}{qtquickcontrols2.conf
197
configuration file}
198
\endlist
199
200
\note you can only dynamically choose the fallback style if it hasn't been
201
chosen statically in the main style's qmldir file.
202
203
The benefit of run-time style selection is that a single application binary
204
can support multiple styles, meaning that the end user can choose which
205
style to run the application with.
206
207
A disadvantage of this approach is that \l {The QML script compiler}
208
{QML compiler} can't know which specific style is in use and therefore
209
cannot generate C++ code for bindings on properties of Qt Quick Controls
210
types. This does not affect the QML compiler's abilities to generate C++
211
for bindings on types from other modules.
212
213
See \l {Mixing Style Selection} for information about mixing
214
run-time and compile-time style selection.
215
216
\section2 Style-specific APIs
217
218
Several styles expose APIs specific to that style, for example the
219
\l{Material Style} attached object or the \l{Universal Style} attached
220
object. These style-specific APIs are only available when their style is
221
actually selected, directly or indirectly, using either compile-time or
222
run-time style selection.
223
224
\section2 Mixing Style Selection
225
226
It is recommended to only use either compile-time or run-time style
227
selection in your application. However, if your application loads third
228
party QML code, for example, it may not be possible to control which
229
imports are used. If you do mix the two approaches, be aware of the
230
following limitations:
231
232
\list
233
\li Compile-time style selection overrides run-time style selection.
234
\li The style that you want to use should always be explicitly imported
235
before any other Controls import. If you don't do this, theming (such
236
as fonts and palettes) will not behave as expected. The first
237
explicitly imported style is also what QQuickStyle::name() will report.
238
\omit
239
(Also, \e only the first imported style's QQuick*Theme::initialize()
240
will be called (assuming it's one of the built-in styles). This is not
241
unique to compile-time selection, as only one theme's initialize
242
function is ever called, but it is worth pointing out that the order
243
matters)
244
\endomit
245
\li The last explicitly imported style is what will actually be used. For
246
example, if you import \c QtQuick.Controls first and then
247
\c QtQuick.Controls.Material, the Material style's Button.qml will be
248
used when a Button is created.
249
Due to the previous point about theming, it is for this reason that you
250
should never explicitly import two different styles in the same
251
application.
252
\li If you intend to use compile-time style selection but load code that
253
imports \c QtQuick.Controls, be aware that calling QQuickStyle::name()
254
before a style has been explicitly imported will cause the platform
255
default to be reported. If you can't avoid this, set the style to match
256
the compile-time one beforehand via \l QQuickStyle::setStyle() or one
257
of the other ways listed in \l {Run-Time Style Selection}.
258
\endlist
259
260
\section3 Using QQuickStyle in C++
261
262
\l[CPP]{QQuickStyle} provides C++ API for configuring a specific
263
style. The following example runs a Qt Quick Controls application
264
with the Material style:
265
266
\code
267
QQuickStyle::setStyle("Material");
268
\endcode
269
270
See the detailed description of \l[CPP]{QQuickStyle} for more
271
details.
272
273
\section3 Command line argument
274
275
Passing a \c -style command line argument is the convenient way to test different
276
styles. It takes precedence over the other methods listed below. The following
277
example runs a Qt Quick Controls application with the Material style:
278
279
\code
280
./app -style Material
281
\endcode
282
283
\section3 Environment variable
284
285
Setting the \c QT_QUICK_CONTROLS_STYLE environment variable can be used to set
286
a system-wide style preference. It takes precedence over the configuration file
287
mentioned below. The following example runs a Qt Quick Controls application with
288
the Universal style:
289
290
\code
291
QT_QUICK_CONTROLS_STYLE=Universal ./app
292
\endcode
293
294
See \l {Supported Environment Variables in Qt Quick Controls} for the full list
295
of supported environment variables.
296
297
\section3 Configuration file
298
299
Qt Quick Controls support a special configuration file, \c :/qtquickcontrols2.conf,
300
that is built into an application's resources.
301
302
The configuration file can specify the preferred style (may be overridden by either
303
of the methods described earlier) and certain style-specific attributes. The following
304
example specifies that the preferred style is the Material style.
305
306
\code
307
[Controls]
308
Style=Material
309
\endcode
310
311
See \l {Qt Quick Controls Configuration File} for more details about the
312
configuration file.
313
314
\section1 Related Information
315
\list
316
\li \l {Basic Style}
317
\li \l {Fusion Style}
318
\li \l {Imagine Style}
319
\li \l {Material Style}
320
\li \l {Universal Style}
321
\li \l {FluentWinUI3 Style}
322
\li \l {Customizing Qt Quick Controls}
323
\li \l {Using File Selectors with Qt Quick Controls}
324
\li \l {Deploying Qt Quick Controls Applications}
325
\li \l {Qt Quick Controls Configuration File}
326
\li \l {Supported Environment Variables in Qt Quick Controls}
327
\endlist
328
*/
qtdeclarative
src
quickcontrols
doc
src
qtquickcontrols-styles.qdoc
Generated on
for Qt by
1.16.1