QQuickStyle 类

The QQuickStyle class allows configuring the application style. 更多...

头: #include <QQuickStyle>
qmake: QT += quickcontrols2
Since: Qt 5.7

静态公共成员

void addStylePath (const QString & path )
QStringList availableStyles ()
QString name ()
QString path ()
void setFallbackStyle (const QString & style )
void setStyle (const QString & style )
QStringList stylePathList ()

详细描述

The QQuickStyle class allows configuring the application style.

QQuickStyle provides API for querying and configuring the application styles of Qt Quick Controls 2.

#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();
}
					

注意: The style must be configured before loading QML that imports Qt Quick Controls 2. 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" 。见 创建自定义样式 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");
					

另请参阅 Styling Qt Quick Controls 2 .

成员函数文档编制

[static] void QQuickStyle:: addStylePath (const QString & path )

添加 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 ().

该函数在 Qt 5.12 引入。

另请参阅 stylePathList () 和 availableStyles ().

[static] QStringList QQuickStyle:: availableStyles ()

Returns the names of the available styles.

注意: The method must be called after creating an instance of QGuiApplication .

该函数在 Qt 5.9 引入。

另请参阅 stylePathList () 和 addStylePath ().

[static] QString QQuickStyle:: name ()

Returns the name of the application style.

注意: 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.

注意: 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 .

注意: The fallback style must be the name of one of the built-in Qt Quick Controls 2 styles, e.g. "Material".

注意: The style must be configured before loading QML that imports Qt Quick Controls 2. 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 环境变量 .

该函数在 Qt 5.8 引入。

另请参阅 setStyle () 和 Using Styles in Qt Quick Controls 2 .

[static] void QQuickStyle:: setStyle (const QString & style )

把应用程序样式设为 style .

注意: The style must be configured before loading QML that imports Qt Quick Controls 2. It is not possible to change the style after the QML types have been registered.

另请参阅 setFallbackStyle () 和 Using Styles in Qt Quick Controls 2 .

[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 子目录在 QQmlEngine::importPathList ().

该函数在 Qt 5.12 引入。

另请参阅 addStylePath () 和 availableStyles ().