Qt Quick Controls Configuration File¶
Qt Quick Controls support a special configuration file,
qtquickcontrols2.conf, which is built into an application’s resources.
The configuration file can specify the preferred style and certain style-specific attributes. The following example specifies that the preferred style is the Material style . Furthermore, when the application is run with the Material style, its theme is light and the accent and primary colors are teal and blue grey, respectively. However, if the application is run with the Universal style instead, the accent color is red and the appropriate theme is chosen based on the system theme colors.
[Controls] Style=Material [Universal] Theme=System Accent=Red [Material] Theme=Light Accent=Teal Primary=BlueGrey
It is possible to specify a custom location for the configuration file with the QT_QUICK_CONTROLS_CONF environment variable.
The following values can be specified in a
Controls section of the configuration file:
The following table lists values that can be used to configure the Imagine style in an
Imagine section of the configuration file:
Specifies the path to the directory that contains the Imagine style assets. If not specified, the built-in assets are used.
For example, to specify a path to a directory stored in the resource system :[Imagine] Path=:/imagine-assets
To specify a relative path to a local directory:[Imagine] Path=imagine-assets
Due to a technical limitation, the path should not be named “imagine” if it is relative to the
The following table lists values that can be used to configure the Material style in a
Material section of the configuration file:
Specifies the default Material theme . The value can be one of the available themes, for example
Specifies the Material variant. The Material Design has two variants: a normal variant designed for touch devices, and a dense variant for desktop. The dense variant uses smaller sizes for controls and their fonts.
The value can be
The following table lists values that can be used to configure the Universal style in a
Universal section of the configuration file:
Specifies the default Universal theme . The value can be one of the available themes, for example
The default font can be specified in a
Font sub-group in each style’s section in the configuration file. The
Font sub-group can be defined in two alternative ways:
[Basic] Font\Family=Open Sans Font\PixelSize=20 [Material\Font] Family=Open Sans PixelSize=20
Supported font attributes:
style hint. Available values:
weight. Qt uses a weighting scale from
1000compatible with OpenType. A weight of
1will be thin, whilst
1000will be extremely black. Available pre-defined weights:
style. Available values:
palette can be configured for each style using the
Palette sub-group in the configuration file. The
Palette sub-group can be defined in two alternative ways:
[Fusion] Palette\Window=#dedede Palette\WindowText=#212121
[Fusion\Palette] Window=#dedede WindowText=#212121
See Palette QML type for more information.
Using the Configuration File in a Project¶
In order to make it possible for Qt Quick Controls to find the configuration file, it must be built into application’s resources using the The Qt Resource System . Here’s an example
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="/"> <file>qtquickcontrols2.conf</file> </qresource> </RCC>
Qt Quick Controls uses a file selector to load the configuration file. It is possible to provide a different configuration file for different platforms and locales. See
QFileSelector documentation for more details.
.qrc file must be listed in the application’s
.pro file so that the build system knows about it. For example:
RESOURCES = application.qrc
© 2022 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.