1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5 \page qtquickcontrols-material.html
8 The Material Style is based on the Google Material Design Guidelines.
9 \l{detailed-desc-material}{More...}
11 \styleimport {QtQuick.Controls.Material 2.12} {Qt 5.7}
13 \section1 Attached Properties
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
26 \section1 Attached Methods
29 \li color \l {material-color-attached-method}{\b color}(enumeration predefined, enumeration shade)
32 \section1 Detailed Description
33 \target detailed-desc-material
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.
39 \include style-screenshots.qdocinc {file} {Material} {material}
41 To run an application with the Material style, see
42 \l {Using Styles in Qt Quick Controls}.
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
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.
55 \section2 Customization
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}:
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}
69 \image qtquickcontrols-material-attributes.png
71 The remaining attributes do not propagate to children:
73 \li \l {material-elevation-attached-prop}{elevation}
74 \li \l {material-roundedScale-attached-prop}{roundedScale}
75 \li \l {material-containerStyle-attached-prop}{containerStyle}
78 In the following example, the window and all three radio buttons appear in
79 the dark theme using a purple accent color:
86 import QtQuick.Controls
87 import QtQuick.Controls.Material
92 Material.theme: Material.Dark
93 Material.accent: Material.Purple
96 anchors.centerIn: parent
112 \image qtquickcontrols-material-purple.png
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.
119 \section3 Configuration File
121 \include qquickmaterialstyle.qdocinc conf
123 See \l {Qt Quick Controls Configuration File} for more details about the
126 \section3 Environment Variables
128 \include qquickmaterialstyle.qdocinc env
130 See \l {Supported Environment Variables in Qt Quick Controls} for the full
131 list of supported environment variables.
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.
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
148 \section2 Pre-defined Material Colors
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:
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} {}
175 When the dark theme is in use, different \l {Pre-defined Shades}{shades} of
176 the pre-defined colors are used by default:
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} {}
198 \section2 Pre-defined Shades
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
219 \b {See also} \l {Basic Style}, \l {Universal Style}
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.
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.
234 The following images illustrate the differences between some of the
235 controls when using the normal and dense variants:
240 \image qtquickcontrols-material-variant-normal.png
242 \image qtquickcontrols-material-variant-dense.png
245 Note that the heights shown above may vary based on differences in fonts
248 \section2 Control-Specific Notes
250 \target material-control-specific-notes-textarea
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.
262 \include qquickmaterialstyle.qdocinc placeholder-text-multiple-lines
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.
271 \include qquickmaterialstyle.qdocinc placeholder-text-multiple-lines
273 \section1 Attached Property Documentation
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.
280 The default value is \c Material.Pink.
282 In the following example, the accent color of the highlighted button is
283 changed to \c Material.Orange:
288 \snippet qtquickcontrols-material-accent.qml 1
290 \image qtquickcontrols-material-accent.png
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.
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.
304 The default value is theme-specific (light or dark).
306 In the following example, the background color of the button is changed to
312 \snippet qtquickcontrols-material-background.qml 1
314 \image qtquickcontrols-material-background.png
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
326 The default value is control-specific.
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}:
335 \snippet qtquickcontrols-material-elevation.qml 1
337 \image qtquickcontrols-material-elevation.png
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.
347 The default value is theme-specific (light or dark).
349 In the following example, the foreground color of the button is set to \c
355 \snippet qtquickcontrols-material-foreground.qml 1
357 \image qtquickcontrols-material-foreground.png
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.
367 The primary color is used as the background color of ToolBar by default.
369 The default value is \c Material.Indigo.
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.
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.
383 \value Material.Light Light theme (default)
384 \value Material.Dark Dark theme
385 \value Material.System System theme
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.
391 In the following example, the theme for both the pane and the button is set
397 \snippet qtquickcontrols-material-theme.qml 1
399 \image qtquickcontrols-material-theme.png
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
411 The default value is control-specific.
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
422 This property was added in Qt 6.5.
424 See also: \l {Material Style: Shape}.
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.
435 The default value is control-specific.
438 \value Material.Filled Use the filled container variant if available
439 \value Material.Outlined Use the outlined container variant if available
441 This property was added in Qt 6.5.
443 See also: \l {Material Style: Text Field Containers}.
447 \section1 Attached Method Documentation
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.
458 color: Material.color(Material.Red)
464 \section1 Related Information
467 \li \l{Styling Qt Quick Controls}