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