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 explicitly importing it in QML. For example, to import the Material style:
104
105 \qml
106 // The style must be imported before any other QtQuick.Controls imports
107 // in order for run-time style selection API like QQuickStyle::name() to
108 // work.
109 import QtQuick.Controls.Material
110
111 ApplicationWindow {
112 // ...
113 }
114 \endqml
115
116 Notice that \c {QtQuick.Controls} (which is responsible for run-time style
117 selection) is not imported. The fallback style is specified by the qmldir
118 of the style:
119
120 \badcode
121 module QtQuick.Controls.Material
122 # ...
123 import QtQuick.Controls.Basic auto
124 \endcode
125
126 The benefit of compile-time style selection is that the
127 \l {The QML script compiler}{QML compiler} knows which specific style
128 is in use and can generate C++ code for bindings.
129
130 Another benefit is that the \c {QtQuick.Controls} plugin is not used and
131 therefore does not need to be deployed with the application.
132
133 Explicit imports are also necessary if your application is built
134 \l {Static Builds}{statically}.
135
136 A disadvantage of compile-time style selection is that one executable
137 cannot support multiple styles, as each style requires its own.
138
139 See \l {Mixing Style Selection} for information about mixing
140 compile-time and run-time style selection.
141
142 \section2 Run-Time Style Selection
143
144 Run-time style selection is a way of specifying a style to use by importing
145 \c QtQuick.Controls:
146
147 \qml
148 import QtQuick.Controls
149 \endqml
150
151 The \c{QtQuick.Controls} plugin will import the style that was set at runtime
152 via one of the following approaches:
153
154 \list
155 \li \l[CPP]{QQuickStyle::setStyle()}
156 \li The \c -style command line argument
157 \li The \l {Supported Environment Variables in Qt Quick Controls}
158 {QT_QUICK_CONTROLS_STYLE environment variable}
159 \li The \l {Qt Quick Controls Configuration File}{qtquickcontrols2.conf
160 configuration file}
161 \endlist
162
163 The priority of these approaches follows the order they are listed,
164 from highest to lowest. That is, using \c QQuickStyle to set the style will
165 always take priority over using the command line argument, for example.
166
167 Similarly, the fallback style can be set via one of the following methods:
168 \list
169 \li \l[CPP]{QQuickStyle::setFallbackStyle()}
170 \li The \l {Supported Environment Variables in Qt Quick Controls}
171 {QT_QUICK_CONTROLS_FALLBACK_STYLE environment variable}
172 \li The \l {Qt Quick Controls Configuration File}{qtquickcontrols2.conf
173 configuration file}
174 \endlist
175
176 \note you can only dynamically choose the fallback style if it hasn't been
177 chosen statically in the main style's qmldir file.
178
179 The benefit of run-time style selection is that a single application binary
180 can support multiple styles, meaning that the end user can choose which
181 style to run the application with.
182
183 A disadvantage of this approach is that \l {The QML script compiler}
184 {QML compiler} can't know which specific style is in use and therefore
185 cannot generate C++ code for bindings on properties of Qt Quick Controls
186 types. This does not affect the QML compiler's abilities to generate C++
187 for bindings on types from other modules.
188
189 See \l {Mixing Style Selection} for information about mixing
190 run-time and compile-time style selection.
191
192 \section2 Mixing Style Selection
193
194 It is recommended to only use either compile-time or run-time style
195 selection in your application. However, if your application loads third
196 party QML code, for example, it may not be possible to control which
197 imports are used. If you do mix the two approaches, be aware of the
198 following limitations:
199
200 \list
201 \li Compile-time style selection overrides run-time style selection.
202 \li The style that you want to use should always be explicitly imported
203 before any other Controls import. If you don't do this, theming (such
204 as fonts and palettes) will not behave as expected. The first
205 explicitly imported style is also what QQuickStyle::name() will report.
206 \omit
207 (Also, \e only the first imported style's QQuick*Theme::initialize()
208 will be called (assuming it's one of the built-in styles). This is not
209 unique to compile-time selection, as only one theme's initialize
210 function is ever called, but it is worth pointing out that the order
211 matters)
212 \endomit
213 \li The last explicitly imported style is what will actually be used. For
214 example, if you import \c QtQuick.Controls first and then
215 \c QtQuick.Controls.Material, the Material style's Button.qml will be
216 used when a Button is created.
217 Due to the previous point about theming, it is for this reason that you
218 should never explicitly import two different styles in the same
219 application.
220 \li If you intend to use compile-time style selection but load code that
221 imports \c QtQuick.Controls, be aware that calling QQuickStyle::name()
222 before a style has been explicitly imported will cause the platform
223 default to be reported. If you can't avoid this, set the style to match
224 the compile-time one beforehand via \l QQuickStyle::setStyle() or one
225 of the other ways listed in \l {Run-Time Style Selection}.
226 \endlist
227
228 \section3 Using QQuickStyle in C++
229
230 \l[CPP]{QQuickStyle} provides C++ API for configuring a specific
231 style. The following example runs a Qt Quick Controls application
232 with the Material style:
233
234 \code
235 QQuickStyle::setStyle("Material");
236 \endcode
237
238 See the detailed description of \l[CPP]{QQuickStyle} for more
239 details.
240
241 \section3 Command line argument
242
243 Passing a \c -style command line argument is the convenient way to test different
244 styles. It takes precedence over the other methods listed below. The following
245 example runs a Qt Quick Controls application with the Material style:
246
247 \code
248 ./app -style Material
249 \endcode
250
251 \section3 Environment variable
252
253 Setting the \c QT_QUICK_CONTROLS_STYLE environment variable can be used to set
254 a system-wide style preference. It takes precedence over the configuration file
255 mentioned below. The following example runs a Qt Quick Controls application with
256 the Universal style:
257
258 \code
259 QT_QUICK_CONTROLS_STYLE=Universal ./app
260 \endcode
261
262 See \l {Supported Environment Variables in Qt Quick Controls} for the full list
263 of supported environment variables.
264
265 \section3 Configuration file
266
267 Qt Quick Controls support a special configuration file, \c :/qtquickcontrols2.conf,
268 that is built into an application's resources.
269
270 The configuration file can specify the preferred style (may be overridden by either
271 of the methods described earlier) and certain style-specific attributes. The following
272 example specifies that the preferred style is the Material style.
273
274 \code
275 [Controls]
276 Style=Material
277 \endcode
278
279 See \l {Qt Quick Controls Configuration File} for more details about the
280 configuration file.
281
282 \section1 Related Information
283 \list
284 \li \l {Basic Style}
285 \li \l {Fusion Style}
286 \li \l {Imagine Style}
287 \li \l {Material Style}
288 \li \l {Universal Style}
289 \li \l {FluentWinUI3 Style}
290 \li \l {Customizing Qt Quick Controls}
291 \li \l {Using File Selectors with Qt Quick Controls}
292 \li \l {Deploying Qt Quick Controls Applications}
293 \li \l {Qt Quick Controls Configuration File}
294 \li \l {Supported Environment Variables in Qt Quick Controls}
295 \endlist
296*/