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