Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qtquickcontrols-material.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-material.html
6 \title Material Style
7
8 The Material Style is based on the Google Material Design Guidelines.
9 \l{detailed-desc-material}{More...}
10
11 \styleimport {QtQuick.Controls.Material 2.12} {Qt 5.7}
12
13 \section1 Attached Properties
14
15 \list
16 \li \l {material-accent-attached-prop}{\b accent} : color
17 \li \l {material-background-attached-prop}{\b background} : color
18 \li \l {material-elevation-attached-prop}{\b elevation} : int
19 \li \l {material-foreground-attached-prop}{\b foreground} : color
20 \li \l {material-primary-attached-prop}{\b primary} : color
21 \li \l {material-theme-attached-prop}{\b theme} : enumeration
22 \li \l {material-roundedScale-attached-prop}{\b roundedScale} : enumeration
23 \li \l {material-containerStyle-attached-prop}{\b containerStyle} : enumeration
24 \endlist
25
26 \section1 Attached Methods
27
28 \list
29 \li color \l {material-color-attached-method}{\b color}(enumeration predefined, enumeration shade)
30 \endlist
31
32 \section1 Detailed Description
33 \target detailed-desc-material
34
35 The Material style is based on the \l {https://www.google.com/design/spec/material-design/introduction.html}
36 {Google Material Design Guidelines}. It allows for a unified experience
37 across platforms and device sizes.
38
39 \include style-screenshots.qdocinc {file} {Material} {material}
40
41 To run an application with the Material style, see
42 \l {Using Styles in Qt Quick Controls}.
43
44 \note The Material style is not a native Android style. The Material
45 style is a 100% cross-platform Qt Quick Controls style implementation that
46 follows the Google Material Design Guidelines. The style runs on any
47 platform, and looks more or less identical everywhere. Minor differences
48 may occur due to differences in available system fonts and font rendering
49 engines.
50
51 \section2 Customization
52
53 The Material style allows customizing five attributes, \l {material-theme-attached-prop}{theme},
54 \l {material-primary-attached-prop}{primary}, \l {material-accent-attached-prop}{accent},
55 \l {material-foreground-attached-prop}{foreground}, and \l {material-background-attached-prop}{background}.
56
57 \image qtquickcontrols-material-attributes.png
58
59 All attributes can be specified for any window or item, and they automatically
60 propagate to children in the same manner as \l {Control::font}{fonts}. In the
61 following example, the window and all three radio buttons appear in the dark
62 theme using a purple accent color:
63
64 \table
65 \row
66 \li
67 \qml
68 import QtQuick 2.12
69 import QtQuick.Controls 2.12
70 import QtQuick.Controls.Material 2.12
71
72 ApplicationWindow {
73 visible: true
74
75 Material.theme: Material.Dark
76 Material.accent: Material.Purple
77
78 Column {
79 anchors.centerIn: parent
80
81 RadioButton { text: qsTr("Small") }
82 RadioButton { text: qsTr("Medium"); checked: true }
83 RadioButton { text: qsTr("Large") }
84 }
85 }
86 \endqml
87 \li
88 \image qtquickcontrols-material-purple.png
89 \endtable
90
91 In addition to specifying the attributes in QML, it is also possible to
92 specify them via environment variables or in a configuration file. Attributes
93 specified in QML take precedence over all other methods.
94
95 \section3 Configuration File
96
97 \include qquickmaterialstyle.qdocinc conf
98
99 See \l {Qt Quick Controls Configuration File} for more details about the
100 configuration file.
101
102 \section3 Environment Variables
103
104 \include qquickmaterialstyle.qdocinc env
105
106 See \l {Supported Environment Variables in Qt Quick Controls} for the full
107 list of supported environment variables.
108
109 \section2 Dependency
110
111 The Material style must be separately imported to gain access to the
112 attributes that are specific to the Material style. It should be noted
113 that regardless of the references to the Material style, the same
114 application code runs with any other style. Material-specific attributes
115 only have an effect when the application is run with the Material style.
116
117 If the Material style is imported in a QML file that is always loaded, the
118 Material style must be deployed with the application in order to be able
119 to run the application regardless of which style the application is run with.
120 By using \l {Using File Selectors with Qt Quick Controls}{file selectors},
121 style-specific tweaks can be applied without creating a hard dependency to
122 a style.
123
124 \section2 Pre-defined Material Colors
125
126 Even though primary and accent can be any \l {colorvaluetypedocs}{color}, it
127 is recommended to use one of the pre-defined colors that have been designed
128 to work well with the rest of the Material style palette:
129
130 Available pre-defined colors:
131 \value Material.Red \stylecolor {#F44336} {}
132 \value Material.Pink \stylecolor {#E91E63} {(default accent)}
133 \value Material.Purple \stylecolor {#9C27B0} {}
134 \value Material.DeepPurple \stylecolor {#673AB7} {}
135 \value Material.Indigo \stylecolor {#3F51B5} {(default primary)}
136 \value Material.Blue \stylecolor {#2196F3} {}
137 \value Material.LightBlue \stylecolor {#03A9F4} {}
138 \value Material.Cyan \stylecolor {#00BCD4} {}
139 \value Material.Teal \stylecolor {#009688} {}
140 \value Material.Green \stylecolor {#4CAF50} {}
141 \value Material.LightGreen \stylecolor {#8BC34A} {}
142 \value Material.Lime \stylecolor {#CDDC39} {}
143 \value Material.Yellow \stylecolor {#FFEB3B} {}
144 \value Material.Amber \stylecolor {#FFC107} {}
145 \value Material.Orange \stylecolor {#FF9800} {}
146 \value Material.DeepOrange \stylecolor {#FF5722} {}
147 \value Material.Brown \stylecolor {#795548} {}
148 \value Material.Grey \stylecolor {#9E9E9E} {}
149 \value Material.BlueGrey \stylecolor {#607D8B} {}
150
151 When the dark theme is in use, different \l {Pre-defined Shades}{shades} of
152 the pre-defined colors are used by default:
153
154 \value Material.Red \stylecolor {#EF9A9A} {}
155 \value Material.Pink \stylecolor {#F48FB1} {(default accent)}
156 \value Material.Purple \stylecolor {#CE93D8} {}
157 \value Material.DeepPurple \stylecolor {#B39DDB} {}
158 \value Material.Indigo \stylecolor {#9FA8DA} {(default primary)}
159 \value Material.Blue \stylecolor {#90CAF9} {}
160 \value Material.LightBlue \stylecolor {#81D4FA} {}
161 \value Material.Cyan \stylecolor {#80DEEA} {}
162 \value Material.Teal \stylecolor {#80CBC4} {}
163 \value Material.Green \stylecolor {#A5D6A7} {}
164 \value Material.LightGreen \stylecolor {#C5E1A5} {}
165 \value Material.Lime \stylecolor {#E6EE9C} {}
166 \value Material.Yellow \stylecolor {#FFF59D} {}
167 \value Material.Amber \stylecolor {#FFE082} {}
168 \value Material.Orange \stylecolor {#FFCC80} {}
169 \value Material.DeepOrange \stylecolor {#FFAB91} {}
170 \value Material.Brown \stylecolor {#BCAAA4} {}
171 \value Material.Grey \stylecolor {#EEEEEE} {}
172 \value Material.BlueGrey \stylecolor {#B0BEC5} {}
173
174 \section2 Pre-defined Shades
175
176 There are several different
177 \l {https://material.google.com/style/color.html#color-color-palette}{shades}
178 of each \l {Pre-defined Material Colors}{pre-defined color} that can be passed
179 to the \l {material-color-attached-method}{Material.color()} function:
180 \value Material.Shade50
181 \value Material.Shade100
182 \value Material.Shade200
183 \value Material.Shade300
184 \value Material.Shade400
185 \value Material.Shade500
186 \value Material.Shade600
187 \value Material.Shade700
188 \value Material.Shade800
189 \value Material.Shade900
190 \value Material.ShadeA100
191 \value Material.ShadeA200
192 \value Material.ShadeA400
193 \value Material.ShadeA700
194
195 \b {See also} \l {Basic Style}, \l {Universal Style}
196
197 \section2 Variants
198
199 The Material style also supports a dense variant, where controls like
200 buttons and delegates are smaller in height and use smaller font sizes.
201 It is recommended to use the dense variant on desktop platforms, where
202 a mouse and keyboard allow more precise and flexible user interaction.
203
204 To use the dense variant, either set the
205 \c QT_QUICK_CONTROLS_MATERIAL_VARIANT environment variable to \c Dense,
206 or specify \c Variant=Dense in the
207 \l {Qt Quick Controls Configuration File}{qtquickcontrols2.conf} file.
208 The default value in both cases is \c Normal.
209
210 The following images illustrate the differences between some of the
211 controls when using the normal and dense variants:
212
213 \table
214 \row
215 \li
216 \image qtquickcontrols-material-variant-normal.png
217 \li
218 \image qtquickcontrols-material-variant-dense.png
219 \endtable
220
221 Note that the heights shown above may vary based on differences in fonts
222 across platforms.
223
224 \section2 Control-Specific Notes
225
226 \target material-control-specific-notes-textarea
227 \section3 TextArea
228
229 TextArea supports two
230 \l {material-containerStyle-attached-prop}{containerStyles}: \c Filled and
231 \c Outlined. Outlined TextAreas have floating placeholder text that sits at
232 the top of the control. This requires the placeholder text to go outside
233 the bounds of the control, which can cause it to be
234 clipped when the TextArea or the Flickable it's a child of sets
235 \l {Item::}{clip} to \c true. To avoid this, \l {Control::}{topInset} is
236 set to an appropriate value in these cases.
237
238 \section3 TextField
239
240 The same \l {material-control-specific-notes-textarea}{issue with clipping}
241 explained above for TextArea can also occur with \l TextField. To avoid
242 this, \l {Control::}{topInset} is set to an appropriate value when the
243 TextField sets clip to \c true.
244
245 \section1 Attached Property Documentation
246
247 \styleproperty {Material.accent} {color} {material-accent-attached-prop}
248 \target material-accent-attached-prop
249 This attached property holds the accent color of the theme. The property
250 can be attached to any window or item. The value is propagated to children.
251
252 The default value is \c Material.Pink.
253
254 In the following example, the accent color of the highlighted button is
255 changed to \c Material.Orange:
256
257 \table
258 \row
259 \li
260 \snippet qtquickcontrols-material-accent.qml 1
261 \li
262 \image qtquickcontrols-material-accent.png
263 \endtable
264
265 \note Even though the accent can be any \l {colorvaluetypedocs}{color}, it is
266 recommended to use one of the \l {pre-defined Material colors} that have been
267 designed to work well with the rest of the Material style palette.
268
269 \endstyleproperty
270
271 \styleproperty {Material.background} {color} {material-background-attached-prop}
272 \target material-background-attached-prop
273 This attached property holds the background color of the theme. The property
274 can be attached to any window or item. The value is propagated to children.
275
276 The default value is theme-specific (light or dark).
277
278 In the following example, the background color of the button is changed to
279 \c Material.Teal:
280
281 \table
282 \row
283 \li
284 \snippet qtquickcontrols-material-background.qml 1
285 \li
286 \image qtquickcontrols-material-background.png
287 \endtable
288
289 \endstyleproperty
290
291 \styleproperty {Material.elevation} {int} {material-elevation-attached-prop}
292 \target material-elevation-attached-prop
293 This attached property holds the elevation of the control. The higher the
294 elevation, the deeper the shadow. The property can be attached to any control,
295 but not all controls visualize elevation.
296
297 The default value is control-specific.
298
299 In the following example, the elevation of the pane is set to \c 6
300 in order to achieve the look of an
301 \l {https://material.google.com/components/cards.html}{elevated card}:
302
303 \table
304 \row
305 \li
306 \snippet qtquickcontrols-material-elevation.qml 1
307 \li
308 \image qtquickcontrols-material-elevation.png
309 \endtable
310
311 \endstyleproperty
312
313 \styleproperty {Material.foreground} {color} {material-foreground-attached-prop}
314 \target material-foreground-attached-prop
315 This attached property holds the foreground color of the theme. The property
316 can be attached to any window or item. The value is propagated to children.
317
318 The default value is theme-specific (light or dark).
319
320 In the following example, the foreground color of the button is set to \c
321 Material.Pink:
322
323 \table
324 \row
325 \li
326 \snippet qtquickcontrols-material-foreground.qml 1
327 \li
328 \image qtquickcontrols-material-foreground.png
329 \endtable
330
331 \endstyleproperty
332
333 \styleproperty {Material.primary} {color} {material-primary-attached-prop}
334 \target material-primary-attached-prop
335 This attached property holds the primary color of the theme. The property
336 can be attached to any window or item. The value is propagated to children.
337
338 The primary color is used as the background color of ToolBar by default.
339
340 The default value is \c Material.Indigo.
341
342 \note Even though the primary can be any \l {colorvaluetypedocs}{color}, it is
343 recommended to use one of the \l {pre-defined Material colors} that have been
344 designed to work well with the rest of the Material style palette.
345
346 \endstyleproperty
347
348 \styleproperty {Material.theme} {enumeration} {material-theme-attached-prop}
349 \target material-theme-attached-prop
350 This attached property holds whether the theme is light or dark. The property
351 can be attached to any window or item. The value is propagated to children.
352
353 Available themes:
354 \value Material.Light Light theme (default)
355 \value Material.Dark Dark theme
356 \value Material.System System theme
357
358 Setting the theme to \c System chooses either the light or dark theme based
359 on the system theme colors. However, when reading the value of the theme
360 property, the value is never \c System, but the actual theme.
361
362 In the following example, the theme for both the pane and the button is set
363 to \c Material.Dark:
364
365 \table
366 \row
367 \li
368 \snippet qtquickcontrols-material-theme.qml 1
369 \li
370 \image qtquickcontrols-material-theme.png
371 \endtable
372
373 \endstyleproperty
374
375 \styleproperty {Material.roundedScale} {enumeration} {material-roundedScale-attached-prop}
376 \target material-roundedScale-attached-prop
377 This attached property holds the radius of rounded corners used on the
378 target control. The property can be attached to any window or item, but
379 only some controls support it.
380
381 The default value is control-specific.
382
383 Available scales:
384 \value Material.NotRounded Square corners
385 \value Material.ExtraSmallScale Extra small rounded corners
386 \value Material.SmallScale Small rounded corners
387 \value Material.MediumScale Medium rounded corners
388 \value Material.LargeScale Large rounded corners
389 \value Material.ExtraLargeScale Extra large rounded corners
390 \value Material.FullScale Fully rounded corners
391
392 This property was added in Qt 6.5.
393
394 See also: \l {Material Style: Shape}.
395
396 \endstyleproperty
397
398 \styleproperty {Material.containerStyle} {enumeration} {material-containerStyle-attached-prop}
399 \target material-containerStyle-attached-prop
400 This attached property holds the style of the container used by the
401 target control. The property can be attached to any window or item, but
402 only TextField and TextArea support it by default.
403
404 The default value is control-specific.
405
406 Available styles:
407 \value Material.Filled Use the filled container variant if available
408 \value Material.Outlined Use the outlined container variant if available
409
410 This property was added in Qt 6.5.
411
412 See also: \l {Material Style: Text Field Containers}.
413
414 \endstyleproperty
415
416 \section1 Attached Method Documentation
417
418 \stylemethod2 {color} {color} {enumeration} {predefined} {enumeration} {shade} {material-color-attached-method}
419 \target material-color-attached-method
420 This attached method returns the effective color value of the specified
421 \l {pre-defined Material colors}{pre-defined Material color} combined with
422 the given \l {pre-defined shades}{shade}. If omitted, the shade argument
423 defaults to \c Material.Shade500.
424
425 \qml
426 Rectangle {
427 color: Material.color(Material.Red)
428 }
429 \endqml
430
431 \endstylemethod2
432
433 \section1 Related Information
434
435 \list
436 \li \l{Styling Qt Quick Controls}
437 \endlist
438*/