QQuickStyle Class
The QQuickStyle class allows configuring the application style. More...
Header: | #include <QQuickStyle> |
qmake: | QT += quickcontrols2 |
Since: | Qt 5.7 |
This class was introduced in Qt 5.7.
Static Public Members
void | addStylePath(const QString &path) |
QStringList | availableStyles() |
QString | name() |
QString | path() |
void | setFallbackStyle(const QString &style) |
void | setStyle(const QString &style) |
QStringList | stylePathList() |
Detailed Description
QQuickStyle provides API for querying and configuring the application styles of Qt Quick Controls.
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickStyle> int main(int argc, char *argv[]) { QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQuickStyle::setStyle("Material"); QQmlApplicationEngine engine; engine.load(QUrl("qrc:/main.qml")); return app.exec(); }
Note: The style must be configured before loading QML that imports Qt Quick Controls. It is not possible to change the style after the QML types have been registered.
The style can also be specified as a path to a custom style, such as ":/mystyle"
. See Creating a Custom Style for more details about building custom styles. Custom styles do not need to implement all controls. By default, the styling system uses the Default style as a fallback for controls that a custom style does not provide. It is possible to specify a different fallback style to customize or extend one of the built-in styles.
QQuickStyle::setStyle(":/mystyle"); QQuickStyle::setFallbackStyle("Material");
See also Styling Qt Quick Controls.
Member Function Documentation
[static]
void QQuickStyle::addStylePath(const QString &path)
Adds path as a directory where Qt Quick Controls 2 searches for available styles.
The path may be any local filesystem directory or Qt Resource directory. For example, the following paths are all valid:
/path/to/styles/
file:///path/to/styles/
:/path/to/styles/
qrc:/path/to/styles/
)
The path will be converted into canonical form before it is added to the style path list.
The newly added path will be first in the stylePathList().
This function was introduced in Qt 5.12.
See also stylePathList() and availableStyles().
[static]
QStringList QQuickStyle::availableStyles()
Returns the names of the available styles.
Note: The method must be called after creating an instance of QGuiApplication.
This function was introduced in Qt 5.9.
See also stylePathList() and addStylePath().
[static]
QString QQuickStyle::name()
Returns the name of the application style.
Note: The application style can be specified by passing a -style
command line argument. Therefore name()
may not return a fully resolved value if called before constructing a QGuiApplication.
[static]
QString QQuickStyle::path()
Returns the path of an overridden application style, or an empty string if the style is one of the built-in Qt Quick Controls 2 styles.
Note: The application style can be specified by passing a -style
command line argument. Therefore path()
may not return a fully resolved value if called before constructing a QGuiApplication.
[static]
void QQuickStyle::setFallbackStyle(const QString &style)
Sets the application fallback style to style.
Note: The fallback style must be the name of one of the built-in Qt Quick Controls styles, e.g. "Material".
Note: The style must be configured before loading QML that imports Qt Quick Controls. It is not possible to change the style after the QML types have been registered.
The fallback style can be also specified by setting the QT_QUICK_CONTROLS_FALLBACK_STYLE
environment variable.
This function was introduced in Qt 5.8.
See also setStyle() and Using Styles in Qt Quick Controls.
[static]
void QQuickStyle::setStyle(const QString &style)
Sets the application style to style.
Note: The style must be configured before loading QML that imports Qt Quick Controls. It is not possible to change the style after the QML types have been registered.
See also setFallbackStyle() and Using Styles in Qt Quick Controls.
[static]
QStringList QQuickStyle::stylePathList()
Returns the list of directories where Qt Quick Controls 2 searches for available styles.
By default, the list contains paths specified in the QT_QUICK_CONTROLS_STYLE_PATH
environment variable, and any existing QtQuick/Controls.2
sub-directories in QQmlEngine::importPathList().
This function was introduced in Qt 5.12.
See also addStylePath() and availableStyles().
© 2020 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.