Material Style

The Material Style is based on the Google Material Design Guidelines. More...

Import Statement: import QtQuick.Controls.Material 2.0
Since: Qt 5.7

Attached Properties

Attached Methods

  • color color(enumeration predefined, enumeration shade)

Detailed Description

The Material style is based on the Google Material Design Guidelines. It allows for a unified experience across platforms and device sizes.

The Material style in light and dark themes

To run an application with the Material style, see Using Styles in Qt Quick Controls 2.

Note: The Material style is not a native Android style. The Material style is a 100% cross-platform Qt Quick Controls 2 style implementation that follows the Google Material Design Guidelines. The style runs on any platform, and looks more or less identical everywhere. Minor differences may occur due to differences in available system fonts and font rendering engines.

Customization

The Material style allows customizing five attributes, theme, primary, accent, foreground, and background.

The following example illustrates how to create a red stop button with light text:

import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0

Button {
    text: "Stop"
    highlighted: true

    Material.accent: Material.Red
    Material.theme: Material.Dark
}

All attributes can be specified for any window or item, and they automatically propagate to children in the same manner as fonts. In the following example, the window and all three radio buttons appear in the dark theme using a purple accent color:

import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0

ApplicationWindow {
    visible: true

    Material.theme: Material.Dark
    Material.accent: Material.Purple

    Column {
        anchors.centerIn: parent

        RadioButton { text: qsTr("Small") }
        RadioButton { text: qsTr("Medium");  checked: true }
        RadioButton { text: qsTr("Large") }
    }
}

In addition to specifying the attributes in QML, it is also possible to specify them via environment variables or in a configuration file. Attributes specified in QML take precedence over all other methods.

Environment Variables

VariableDescription
QT_QUICK_CONTROLS_MATERIAL_THEMEThe value can be one of the available themes, for example "Dark".
QT_QUICK_CONTROLS_MATERIAL_ACCENTThe value can be any color, but it is recommended to use one of the pre-defined Material colors, for example "Teal".
QT_QUICK_CONTROLS_MATERIAL_PRIMARYThe value can be any color, but it is recommended to use one of the pre-defined Material colors, for example "BlueGrey".
QT_QUICK_CONTROLS_MATERIAL_FOREGROUNDThe value can be any color, or one of the pre-defined Material colors.
QT_QUICK_CONTROLS_MATERIAL_BACKGROUNDThe value can be any color, or one of the pre-defined Material colors.

Dependency

The Material style must be separately imported to gain access to the attributes that are specific to the Material style. It should be noted that regardless of the references to the Material style, the same application code runs with any other style. Material-specific attributes only have an effect when the application is run with the Material style.

If the Material style is imported in a QML file that is always loaded, the Material style must be deployed with the application in order to be able to run the application regardless of which style the application is run with. By using file selectors, style-specific tweaks can be applied without creating a hard dependency to a style.

Pre-defined Material Colors

Even though primary and accent can be any color, it is recommended to use one of the pre-defined colors that have been designed to work well with the rest of the Material style palette:

Available pre-defined colors:

ConstantDescription
Material.Red
#F44336
Material.Pink
#E91E63 (default accent)
Material.Purple
#9C27B0
Material.DeepPurple
#673AB7
Material.Indigo
#3F51B5 (default primary)
Material.Blue
#2196F3
Material.LightBlue
#03A9F4
Material.Cyan
#00BCD4
Material.Teal
#009688
Material.Green
#4CAF50
Material.LightGreen
#8BC34A
Material.Lime
#CDDC39
Material.Yellow
#FFEB3B
Material.Amber
#FFC107
Material.Orange
#FF9800
Material.DeepOrange
#FF5722
Material.Brown
#795548
Material.Grey
#9E9E9E
Material.BlueGrey
#607D8B

When the dark theme is in use, different shades of the pre-defined colors are used by default:

ConstantDescription
Material.Red
#EF9A9A
Material.Pink
#F48FB1 (default accent)
Material.Purple
#CE93D8
Material.DeepPurple
#B39DDB
Material.Indigo
#9FA8DA (default primary)
Material.Blue
#90CAF9
Material.LightBlue
#81D4FA
Material.Cyan
#80DEEA
Material.Teal
#80CBC4
Material.Green
#A5D6A7
Material.LightGreen
#C5E1A5
Material.Lime
#E6EE9C
Material.Yellow
#FFF59D
Material.Amber
#FFE082
Material.Orange
#FFCC80
Material.DeepOrange
#FFAB91
Material.Brown
#BCAAA4
Material.Grey
#EEEEEE
Material.BlueGrey
#B0BEC5

Pre-defined Shades

There are several different shades of each pre-defined color that can be passed to the Material.color() function:

ConstantValue
Material.Shade50
Material.Shade100
Material.Shade200
Material.Shade300
Material.Shade400
Material.Shade500
Material.Shade600
Material.Shade700
Material.Shade800
Material.Shade900
Material.ShadeA100
Material.ShadeA200
Material.ShadeA400
Material.ShadeA700

See also Default Style, Universal Style

Attached Property Documentation

Material.accent : color

This attached property holds the accent color of the theme. The property can be attached to any window or item. The value is propagated to children.

The default value is Material.Pink.

Note: Even though the accent can be any color, it is recommended to use one of the pre-defined Material colors that have been designed to work well with the rest of the Material style palette.


Material.background : color

This attached property holds the background color of the theme. The property can be attached to any window or item. The value is propagated to children.

The default value is theme-specific (light or dark).


Material.elevation : int

This attached property holds the elevation of the control. The higher the elevation, the deeper the shadow. The property can be attached to any control, but not all controls visualize elevation.

The default value is control-specific.


Material.foreground : color

This attached property holds the foreground color of the theme. The property can be attached to any window or item. The value is propagated to children.

The default value is theme-specific (light or dark).


Material.primary : color

This attached property holds the primary color of the theme. The property can be attached to any window or item. The value is propagated to children.

The default value is Material.Indigo.

Note: Even though the primary can be any color, it is recommended to use one of the pre-defined Material colors that have been designed to work well with the rest of the Material style palette.


Material.theme : enumeration

This attached property holds whether the theme is light or dark. The property can be attached to any window or item. The value is propagated to children.

Available themes:

ConstantDescription
Material.LightLight theme (default)
Material.DarkDark theme


Attached Method Documentation

color color(enumeration predefined, enumeration shade)

This attached method returns the effective color value of the specified pre-defined Material color combined with the given shade. If omitted, the shade argument defaults to Material.Shade500.

import QtQuick 2.0
import QtQuick.Controls.Material 2.0

Rectangle {
    color: Material.color(Material.Red)
}


© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.