IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Universal Style

Qt Quick Controls Reference Documentation.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

Universal Style

The Universal Style is based on the Microsoft Universal Design Guidelines. More...

  • Import Statement: import QtQuick.Controls.Universal 2.12

  • Since: Qt 5.7

Attached Properties

Attached Methods

  • color color(enumeration predefined)

Detailed Description

 

The Universal style is a device-agnostic style based on the Microsoft Universal Design Guidelines. The Universal style has been designed to look good on all devices, from phones and tablets to PCs.

   

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

The Universal style is not a native Windows 10 style. The Universal style is a 100% cross-platform Qt Quick Controls style implementation that follows the Microsoft Universal 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 Universal style allows customizing four attributes, theme, accent, foreground, and background.

Image non disponible

Both 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 violet accent color:

 
Sélectionnez
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.Universal 2.12

ApplicationWindow {
    visible: true

    Universal.theme: Universal.Dark
    Universal.accent: Universal.Violet

    Column {
        anchors.centerIn: parent

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

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.

Configuration File

Variable

Description

Theme

Specifies the default Universal theme. The value can be one of the available themes, for example "Dark".

Accent

Specifies the default Universal accent color. The value can be any color, but it is recommended to use one of the pre-defined Universal colors, for example "Violet".

Foreground

Specifies the default Universal foreground color. The value can be any color, or one of the pre-defined Universal colors, for example "Brown".

Background

Specifies the default Universal background color. The value can be any color, or one of the pre-defined Universal colors, for example "Steel".

See Qt Quick Controls Configuration File for more details about the configuration file.

Environment Variables

Variable

Description

QT_QUICK_CONTROLS_UNIVERSAL_THEME

Specifies the default Universal theme. The value can be one of the available themes, for example "Dark".

QT_QUICK_CONTROLS_UNIVERSAL_ACCENT

Specifies the default Universal accent color. The value can be any color, but it is recommended to use one of the pre-defined Universal colors, for example "Violet".

QT_QUICK_CONTROLS_UNIVERSAL_FOREGROUND

Specifies the default Universal foreground color. The value can be any color, or one of the pre-defined Universal colors, for example "Brown".

QT_QUICK_CONTROLS_UNIVERSAL_BACKGROUND

Specifies the default Universal background color. The value can be any color, or one of the pre-defined Universal colors, for example "Steel".

See Supported Environment Variables in Qt Quick Controls for the full list of supported environment variables.

Dependency

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

If the Universal style is imported in a QML file that is always loaded, the Universal 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 Universal Colors

Available pre-defined colors:

Constant

Description

Universal.Lime

#A4C400

Universal.Green

#60A917

Universal.Emerald

#008A00

Universal.Teal

#00ABA9

Universal.Cyan

#1BA1E2

Universal.Cobalt

#3E65FF (default accent)

Universal.Indigo

#6A00FF

Universal.Violet

#AA00FF

Universal.Pink

#F472D0

Universal.Magenta

#D80073

Universal.Crimson

#A20025

Universal.Red

#E51400

Universal.Orange

#FA6800

Universal.Amber

#F0A30A

Universal.Yellow

#E3C800

Universal.Brown

#825A2C

Universal.Olive

#6D8764

Universal.Steel

#647687

Universal.Mauve

#76608A

Universal.Taupe

#87794E

See also Basic Style, Material Style

Attached Property Documentation

 

Universal.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 Universal.Cobalt.

In the following example, the accent color of the highlighted button is changed to Universal.Orange:

 
Sélectionnez
Button {
    text: qsTr("Button")
    highlighted: true
    Universal.accent: Universal.Orange
}
Image non disponible

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

Universal.background : color

{universal-background-attached-prop}   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).

In the following example, the background color of the pane is changed to Universal.Steel:

 
Sélectionnez
Pane {
    Universal.background: Universal.Steel

    Button {
        text: qsTr("Button")
    }
}
Image non disponible

Universal.foreground : color

{universal-foreground-attached-prop}   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).

In the following example, the foreground color of the button is set to Universal.Pink:

 
Sélectionnez
Button {
    text: qsTr("Button")
    Universal.foreground: Universal.Pink
}
Image non disponible

Universal.theme : enumeration

{universal-theme-attached-prop}   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:

Constant

Description

Universal.Light

Light theme (default)

Universal.Dark

Dark theme

Universal.System

System theme

Setting the theme to System chooses either the light or dark theme based on the system theme colors. However, when reading the value of the theme property, the value is never System, but the actual theme.

In the following example, the theme for both the pane and the button is set to Universal.Dark:

 
Sélectionnez
Pane {
    Universal.theme: Universal.Dark

    Button {
        text: qsTr("Button")
    }
}
Image non disponible

Attached Method Documentation

 

color color(enumeration predefined)

{color-attached-method}   This attached method returns the effective color value of the specified pre-defined Universal color.

 
Sélectionnez
Rectangle {
    color: Universal.color(Universal.Red)
}

Related Information

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+