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-universal.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-universal.html
6 \title Universal Style
7
8 The Universal Style is based on the Microsoft Universal Design Guidelines.
9 \l {detailed-desc-universal}{More...}
10
11 \styleimport {QtQuick.Controls.Universal} {Qt 5.7}
12
13 \section1 Attached Properties
14
15 \list
16 \li \l {universal-accent-attached-prop}{\b accent} : color
17 \li \l {universal-background-attached-prop}{\b background} : color
18 \li \l {universal-foreground-attached-prop}{\b foreground} : color
19 \li \l {universal-theme-attached-prop}{\b theme} : enumeration
20 \endlist
21
22 \section1 Attached Methods
23
24 \list
25 \li color \l {color-attached-method}{\b color}(enumeration predefined)
26 \endlist
27
28 \section1 Detailed Description
29 \target detailed-desc-universal
30
31 The Universal style is a device-agnostic style based on the
32 Microsoft Universal Design Guidelines.
33 The Universal style has been designed to look good on all devices, from
34 phones and tablets to PCs.
35
36 \include style-screenshots.qdocinc {file} {Universal} {universal}
37
38 To run an application with the Universal style, see
39 \l {Using Styles in Qt Quick Controls}.
40
41 \note The Universal style is not a native Windows 10 style. The Universal
42 style is a 100% cross-platform Qt Quick Controls style implementation that
43 follows the Microsoft Universal Design Guidelines. The style runs on any
44 platform, and looks more or less identical everywhere. Minor differences
45 may occur due to differences in available system fonts and font rendering
46 engines.
47
48 \section2 Customization
49
50 The Universal style allows customizing four attributes, \l {universal-theme-attached-prop}{theme},
51 \l {universal-accent-attached-prop}{accent}, \l {universal-foreground-attached-prop}{foreground}, and
52 \l {universal-background-attached-prop}{background}.
53
54 \image qtquickcontrols-universal-attributes.png
55 {Universal style buttons showing theme and accent attributes}
56
57 Both attributes can be specified for any window or item, and they automatically
58 propagate to children in the same manner as \l {Control::font}{fonts}. In the
59 following example, the window and all three radio buttons appear in the dark
60 theme using a violet accent color:
61
62 \table
63 \row
64 \li
65 \qml
66 import QtQuick
67 import QtQuick.Controls
68 import QtQuick.Controls.Universal
69
70 ApplicationWindow {
71 visible: true
72
73 Universal.theme: Universal.Dark
74 Universal.accent: Universal.Violet
75
76 Column {
77 anchors.centerIn: parent
78
79 RadioButton { text: qsTr("Small") }
80 RadioButton { text: qsTr("Medium"); checked: true }
81 RadioButton { text: qsTr("Large") }
82 }
83 }
84 \endqml
85 \li
86 \image qtquickcontrols-universal-violet.png
87 {Universal style controls with custom violet accent}
88 \endtable
89
90 In addition to specifying the attributes in QML, it is also possible to
91 specify them via environment variables or in a configuration file. Attributes
92 specified in QML take precedence over all other methods.
93
94 \section3 Configuration File
95
96 \include qquickuniversalstyle.qdocinc conf
97
98 See \l {Qt Quick Controls Configuration File} for more details about the
99 configuration file.
100
101 \section3 Environment Variables
102
103 \include qquickuniversalstyle.qdocinc env
104
105 See \l {Supported Environment Variables in Qt Quick Controls} for the full
106 list of supported environment variables.
107
108 \section2 Dependency
109
110 The Universal style must be separately imported to gain access to the
111 attributes that are specific to the Universal style. It should be noted
112 that regardless of the references to the Universal style, the same
113 application code runs with any other style. Universal-specific attributes
114 only have an effect when the application is run with the Universal style.
115
116 If the Universal style is imported in a QML file that is always loaded, the
117 Universal style must be deployed with the application in order to be able
118 to run the application regardless of which style the application is run with.
119 By using \l {Using File Selectors with Qt Quick Controls}{file selectors},
120 style-specific tweaks can be applied without creating a hard dependency to
121 a style.
122
123 \section2 Pre-defined Universal Colors
124
125 Available pre-defined colors:
126 \value Universal.Lime \stylecolor {#A4C400} {}
127 \value Universal.Green \stylecolor {#60A917} {}
128 \value Universal.Emerald \stylecolor {#008A00} {}
129 \value Universal.Teal \stylecolor {#00ABA9} {}
130 \value Universal.Cyan \stylecolor {#1BA1E2} {}
131 \value Universal.Cobalt \stylecolor {#3E65FF} {(default accent)}
132 \value Universal.Indigo \stylecolor {#6A00FF} {}
133 \value Universal.Violet \stylecolor {#AA00FF} {}
134 \value Universal.Pink \stylecolor {#F472D0} {}
135 \value Universal.Magenta \stylecolor {#D80073} {}
136 \value Universal.Crimson \stylecolor {#A20025} {}
137 \value Universal.Red \stylecolor {#E51400} {}
138 \value Universal.Orange \stylecolor {#FA6800} {}
139 \value Universal.Amber \stylecolor {#F0A30A} {}
140 \value Universal.Yellow \stylecolor {#E3C800} {}
141 \value Universal.Brown \stylecolor {#825A2C} {}
142 \value Universal.Olive \stylecolor {#6D8764} {}
143 \value Universal.Steel \stylecolor {#647687} {}
144 \value Universal.Mauve \stylecolor {#76608A} {}
145 \value Universal.Taupe \stylecolor {#87794E} {}
146
147 \b {See also} \l {Basic Style}, \l {Material Style}
148
149 \section1 Attached Property Documentation
150
151 \styleproperty {Universal.accent} {color}
152 \target universal-accent-attached-prop
153 This attached property holds the accent color of the theme. The property
154 can be attached to any window or item. The value is propagated to children.
155
156 The default value is \c Universal.Cobalt.
157
158 In the following example, the accent color of the highlighted button is
159 changed to \c Universal.Orange:
160
161 \table
162 \row
163 \li
164 \snippet qtquickcontrols-universal-accent.qml 1
165 \li
166 \image qtquickcontrols-universal-accent.png
167 {Universal style controls showing accent color}
168 \endtable
169
170 \note Even though the accent can be any \l {colorvaluetypedocs}{color}, it is
171 recommended to use one of the \l {pre-defined Universal colors} that have been
172 designed to work well with the rest of the Universal style palette.
173
174 \endstyleproperty
175
176 \styleproperty {Universal.background} {color}
177 \target universal-background-attached-prop
178 This attached property holds the background color of the theme. The property
179 can be attached to any window or item. The value is propagated to children.
180
181 The default value is theme-specific (light or dark).
182
183 In the following example, the background color of the pane is changed to
184 \c Universal.Steel:
185
186 \table
187 \row
188 \li
189 \snippet qtquickcontrols-universal-background.qml 1
190 \li
191 \image qtquickcontrols-universal-background.png
192 {Universal style controls showing background color}
193 \endtable
194
195 \endstyleproperty
196
197 \styleproperty {Universal.foreground} {color}
198 \target universal-foreground-attached-prop
199 This attached property holds the foreground color of the theme. The property
200 can be attached to any window or item. The value is propagated to children.
201
202 The default value is theme-specific (light or dark).
203
204 In the following example, the foreground color of the button is set to \c
205 Universal.Pink:
206
207 \table
208 \row
209 \li
210 \snippet qtquickcontrols-universal-foreground.qml 1
211 \li
212 \image qtquickcontrols-universal-foreground.png
213 {Universal style controls showing foreground color}
214 \endtable
215
216 \endstyleproperty
217
218 \styleproperty {Universal.theme} {enumeration}
219 \target universal-theme-attached-prop
220 This attached property holds whether the theme is light or dark. The property
221 can be attached to any window or item. The value is propagated to children.
222
223 Available themes:
224 \value Universal.Light Light theme (default)
225 \value Universal.Dark Dark theme
226 \value Universal.System System theme
227
228 Setting the theme to \c System chooses either the light or dark theme based
229 on the system theme colors. However, when reading the value of the theme
230 property, the value is never \c System, but the actual theme.
231
232 In the following example, the theme for both the pane and the button is set
233 to \c Universal.Dark:
234
235 \table
236 \row
237 \li
238 \snippet qtquickcontrols-universal-theme.qml 1
239 \li
240 \image qtquickcontrols-universal-theme.png
241 {Universal style controls in light and dark themes}
242 \endtable
243
244 \endstyleproperty
245
246 \section1 Attached Method Documentation
247
248 \stylemethod {color} {color} {enumeration} {predefined}
249 \target color-attached-method
250 This attached method returns the effective color value of the specified
251 \l {pre-defined Universal colors}{pre-defined Universal color}.
252
253 \qml
254 Rectangle {
255 color: Universal.color(Universal.Red)
256 }
257 \endqml
258
259 \endstylemethod
260
261 \section1 Related Information
262
263 \list
264 \li \l{Styling Qt Quick Controls}
265 \endlist
266*/