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