Styling Qt Quick Controls#
Qt Quick Controls comes with a selection of styles.
The Basic Style is a simple and light-weight all-round style that offers the maximum performance for Qt Quick Controls.
The Fusion Style is a platform-agnostic style that offers a desktop-oriented look and feel for Qt Quick Controls.
The Imagine Style is based on image assets. The style comes with a default set of images which can easily be changed by providing a directory with images using a predefined naming convention.
The macOS Style is a native-looking style for macOS.
this style is only available for applications running on macOS.
The iOS Style is a native-looking style for iOS based on image assets.
this style is only available for applications running on iOS.
The Material Style offers an appealing design based on the Google Material Design Guidelines , but requires more system resources than the Basic style.
The Universal Style offers an appealing design based on the Microsoft Universal Design Guidelines , but requires more system resources than the Basic style.
The Windows Style is a native-looking style for Windows.
this style is only available for applications running on Windows.
Using Styles in Qt Quick Controls#
If no style is explicitly set, a default style will be used. The style that is used depends on the operating system:
Android: Material Style
Linux: Fusion Style
macOS: macOS Style
Windows: Windows Style
For all other operating systems, the Basic Style is used.
Compile-Time Style Selection#
Compile-time style selection is a way of specifying a style to use by importing it in QML. For example, to import the Material style:
Notice that QtQuick .Controls (which is responsible for run-time style selection) is not imported. The fallback style is specified by the qmldir of the style:
module QtQuick.Controls.Material # ... import QtQuick.Controls.Basic auto
The benefit of compile-time style selection is that the QtQuick .Controls plugin is not used and therefore does not need to be deployed with the application.
Explicit imports are also necessary if your application is built statically .
Run-Time Style Selection#
Run-time style selection is a way of specifying a style to use by importing
The QtQuick .Controls plugin will import the style and fallback style that were set at runtime via one of the following approaches:
-stylecommand line argument
The priority of these approaches follows the order they are listed, from highest to lowest. That is, using
QQuickStyle to set the style will always take priority over using the command line argument, for example.
The benefit of run-time style selection is that a single application binary can support multiple styles, meaning that the end user can choose which style to run the application with.
Using QQuickStyle in C++#
QQuickStyle provides C++ API for configuring a specific style. The following example runs a Qt Quick Controls application with the Material style:
See the detailed description of
QQuickStyle for more details.
Command line argument#
-style command line argument is the convenient way to test different styles. It takes precedence over the other methods listed below. The following example runs a Qt Quick Controls application with the Material style:
./app -style material
QT_QUICK_CONTROLS_STYLE environment variable can be used to set a system-wide style preference. It takes precedence over the configuration file mentioned below. The following example runs a Qt Quick Controls application with the Universal style:
See Supported Environment Variables in Qt Quick Controls for the full list of supported environment variables.
Qt Quick Controls support a special configuration file,
:/qtquickcontrols2.conf, that is built into an application’s resources.
The configuration file can specify the preferred style (may be overridden by either of the methods described earlier) and certain style-specific attributes. The following example specifies that the preferred style is the Material style.
See Qt Quick Controls Configuration File for more details about the configuration file.