Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 \l {https://dev.windows.com/design}{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 \section1 Using Styles in Qt Quick Controls
73
74 \section2 Default Styles
75
76 If no style is explicitly set, a default style will be used. The style that
77 is used depends on the operating system:
78
79 \list
80 \li Android: \l {Material Style}
81 \li iOS: \l {iOS Style}
82 \li Linux: \l {Fusion Style}
83 \li macOS: \l {macOS Style}
84 \li Windows: \l {Windows Style}
85 \endlist
86
87 For all other operating systems, the \l {Basic Style} is used.
88
89 \section2 Compile-Time Style Selection
90
91 Compile-time style selection is a way of specifying a style to use by
92 importing it in QML. For example, to import the Material style:
93
94 \qml
95 import QtQuick.Controls.Material
96
97 ApplicationWindow {
98 // ...
99 }
100 \endqml
101
102 Notice that QtQuick.Controls (which is responsible for run-time style
103 selection) is not imported. The fallback style is specified by the qmldir
104 of the style:
105
106 \badcode
107 module QtQuick.Controls.Material
108 # ...
109 import QtQuick.Controls.Basic auto
110 \endcode
111
112 The benefit of compile-time style selection is that the
113 \l {The QML script compiler}{QML compiler} knows which specific style
114 is in use and can generate C++ code for bindings.
115
116 Another benefit is that the QtQuick.Controls plugin is not used and
117 therefore does not need to be deployed with the application.
118
119 Explicit imports are also necessary if your application is built
120 \l {Static Builds}{statically}.
121
122 A disadvantage of compile-time style selection is that one executable
123 cannot support multiple styles, as each style requires its own.
124
125 \section2 Run-Time Style Selection
126
127 Run-time style selection is a way of specifying a style to use by importing
128 \c QtQuick.Controls:
129
130 \qml
131 import QtQuick.Controls
132 \endqml
133
134 The QtQuick.Controls plugin will import the style and fallback
135 style that were set at runtime via one of the following approaches:
136
137 \list
138 \li \l[CPP]{QQuickStyle::setStyle()}
139 \li The \c -style command line argument
140 \li The \c QT_QUICK_CONTROLS_STYLE environment variable
141 \li The \c qtquickcontrols2.conf configuration file
142 \endlist
143
144 The priority of these approaches follows the order they are listed,
145 from highest to lowest. That is, using \c QQuickStyle to set the style will
146 always take priority over using the command line argument, for example.
147
148 The benefit of run-time style selection is that a single application binary
149 can support multiple styles, meaning that the end user can choose which
150 style to run the application with.
151
152 A disadvantage of this approach is that \l {The QML script compiler}
153 {QML compiler} can't know which specific style is in use and therefore
154 cannot generate C++ code for bindings on properties of Qt Quick Controls
155 types. This does not affect the QML compiler's abilities to generate C++
156 for bindings on types from other modules.
157
158 \section3 Using QQuickStyle in C++
159
160 \l[CPP]{QQuickStyle} provides C++ API for configuring a specific
161 style. The following example runs a Qt Quick Controls application
162 with the Material style:
163
164 \code
165 QQuickStyle::setStyle("Material");
166 \endcode
167
168 See the detailed description of \l[CPP]{QQuickStyle} for more
169 details.
170
171 \section3 Command line argument
172
173 Passing a \c -style command line argument is the convenient way to test different
174 styles. It takes precedence over the other methods listed below. The following
175 example runs a Qt Quick Controls application with the Material style:
176
177 \code
178 ./app -style material
179 \endcode
180
181 \section3 Environment variable
182
183 Setting the \c QT_QUICK_CONTROLS_STYLE environment variable can be used to set
184 a system-wide style preference. It takes precedence over the configuration file
185 mentioned below. The following example runs a Qt Quick Controls application with
186 the Universal style:
187
188 \code
189 QT_QUICK_CONTROLS_STYLE=universal ./app
190 \endcode
191
192 See \l {Supported Environment Variables in Qt Quick Controls} for the full list
193 of supported environment variables.
194
195 \section3 Configuration file
196
197 Qt Quick Controls support a special configuration file, \c :/qtquickcontrols2.conf,
198 that is built into an application's resources.
199
200 The configuration file can specify the preferred style (may be overridden by either
201 of the methods described earlier) and certain style-specific attributes. The following
202 example specifies that the preferred style is the Material style.
203
204 \code
205 [Controls]
206 Style=Material
207 \endcode
208
209 See \l {Qt Quick Controls Configuration File} for more details about the
210 configuration file.
211
212 \section1 Related Information
213 \list
214 \li \l {Basic Style}
215 \li \l {Fusion Style}
216 \li \l {Imagine Style}
217 \li \l {Material Style}
218 \li \l {Universal Style}
219 \li \l {Customizing Qt Quick Controls}
220 \li \l {Using File Selectors with Qt Quick Controls}
221 \li \l {Deploying Qt Quick Controls Applications}
222 \li \l {Qt Quick Controls Configuration File}
223 \li \l {Supported Environment Variables in Qt Quick Controls}
224 \endlist
225*/