Qt 5.6 | Qt Labs Controls | Styling Qt Labs Controls

Qt 5.6.3 Reference Documentation

# Styling Qt Labs Controls

Qt Labs Controls comes with a selection of styles. The Default style is a simple and light-weight all-round style that offers the maximum performance for Qt Labs Controls. The more advanced Universal and Material styles offer an appealing design, but require more system resources.

## Usage

In order to run an application with a specific style, either pass a command line argument, or set an environment variable. Alternatively, the preferred style and style-specific attributes can be specified in a configuration file.

### Command line argument

Passing a `-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 Labs Controls application with the Material style:

      ./app -style material

### Environment variable

Setting the `QT_LABS_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 Labs Controls application with the Universal style:

      QT_LABS_CONTROLS_STYLE=universal ./app

### Configuration file

Qt Labs Controls support a special configuration file, `:/qtlabscontrols.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. Furthermore, when the application is run with the Material style, its theme is light and the accent color is brown. However, if the application is run with the Universal style instead, the theme is dark and the accent color is red.

      [Controls]
      Style=Material

      [Universal]
      Theme=Dark
      Accent=Red

      [Material]
      Theme=Light
      Accent=Brown

In order to make it possible for Qt Labs Controls to find the configuration file, it must be built into application's resources using the The Qt Resource System. Here's an example `.qrc` file:

      <!DOCTYPE RCC><RCC version="1.0">
      <qresource prefix="/">
          <file>qtlabscontrols.conf</file>
      </qresource>
      </RCC>

Note: Qt Labs 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.

Finally, the `.qrc` file must be listed in the application's `.pro` file so that the build system knows about it. For example:

      RESOURCES = application.qrc

## Related Information

- Default Style
- Material Style
- Universal Style