On this page

QStyleKitStyle Class

The QStyleKitStyle class applies a Qt Labs StyleKit style to Qt Widgets. More...

Header: #include <QStyleKitStyle>
Since: Qt 6.12

Properties

Public Functions

QStyleKitStyle()
QStyleKitStyle(const QString &fileName)
virtual ~QStyleKitStyle() override
QStringList customThemeNames() const
void setStylePath(const QString &fileName)
void setThemeName(const QString &themeName)
QString stylePath() const
QString themeName() const
QStringList themeNames() const

Reimplemented Public Functions

virtual void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w = nullptr) const override
virtual void drawControl(QStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const override
virtual void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const override
virtual QStyle::SubControl hitTestComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *w = nullptr) const override
virtual int pixelMetric(QStyle::PixelMetric m, const QStyleOption *opt = nullptr, const QWidget *widget = nullptr) const override
virtual void polish(QApplication *app) override
virtual void polish(QPalette &palette) override
virtual void polish(QWidget *widget) override
virtual QSize sizeFromContents(QStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget = nullptr) const override
virtual QPalette standardPalette() const override
virtual int styleHint(QStyle::StyleHint sh, const QStyleOption *opt = nullptr, const QWidget *w = nullptr, QStyleHintReturn *shret = nullptr) const override
virtual QRect subControlRect(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, QStyle::SubControl sc, const QWidget *w = nullptr) const override
virtual QRect subElementRect(QStyle::SubElement r, const QStyleOption *opt, const QWidget *widget = nullptr) const override
virtual void unpolish(QApplication *app) override
virtual void unpolish(QWidget *widget) override

Signals

Reimplemented Protected Functions

virtual bool eventFilter(QObject *obj, QEvent *event) override

Detailed Description

QStyleKitStyle is a QStyle implementation that uses a StyleKit Style to style Qt Widgets. It loads the Style at the local path specified by stylePath, and uses it to resolve style properties such as colors, fonts, and sizes for widgets in various states, in order to paint them according to the style's design. This allows the same StyleKit style to be shared between Qt Quick Controls and Qt Widgets.

Note: StyleKit is a Qt Labs module, and its API may change between Qt releases.

Loading a Style

A style is a QML file whose root object is a Style. To load it, pass the file path to the constructor or to setStylePath():

auto *style = new QStyleKitStyle(QStringLiteral("qrc:/styles/MyStyle.qml"));
QApplication::setStyle(style);

QStyleKitStyle is also registered as a QStyleFactory plugin under the key StyleKit, which can be selected via the -style command line argument or QApplication::setStyle(). When created through the factory, set stylePath after construction to load a style file.

auto *style = QStyleFactory::create("StyleKit");
style->setProperty("stylePath", QStringLiteral("qrc:/styles/MyStyle.qml"));
QApplication::setStyle(style);

The Style is loaded with an internal QQmlEngine owned by the QStyleKitStyle instance. If the URL is invalid or the root object is not a Style, a warning is emitted and the style behaves like QCommonStyle until a valid stylePath is set.

Themes

A Style may define one or more named themes. The active theme is selected with setThemeName(); the list of available themes is exposed through themeNames. The special theme name System makes the style follow the platform color scheme: when the OS color scheme changes, the active theme is recreated automatically and all widgets are repolished.

See also QStyle, QCommonStyle, QStyleFactory, Qt Labs StyleKit, Style, and Theme.

Property Documentation

stylePath : QString

This property holds the URL of the QML Style file driving this style.

The URL must resolve to a QML component whose root object is a Style. Setting this property reloads the style; if the new file cannot be loaded, the previously loaded style is kept and a warning is emitted.

Note: The file specified by stylePath must be a local file. Remote files (e.g., HTTP URLs) are not supported.

Access functions:

QString stylePath() const
void setStylePath(const QString &fileName)

Notifier signal:

void stylePathChanged()

themeName : QString

This property holds the name of the active theme.

The value must be one of the entries in themeNames, or the special name System to follow the platform color scheme. Setting this property updates all widgets to repaint with the new theme.

Access functions:

QString themeName() const
void setThemeName(const QString &themeName)

Notifier signal:

void themeNameChanged()

[read-only] themeNames : QStringList

This property holds the list of theme names exposed by the loaded Style.

This list includes the built-in Light and Dark themes as well as any custom themes defined by the style.

Access functions:

QStringList themeNames() const

Notifier signal:

Member Function Documentation

QStyleKitStyle::QStyleKitStyle()

Constructs a QStyleKitStyle with no style loaded.

Use setStylePath() to load a QML Style after construction. Until a style is loaded, painting and metrics behave as in QCommonStyle.

QStyleKitStyle::QStyleKitStyle(const QString &fileName)

Constructs a QStyleKitStyle and loads the QML Style at fileName.

fileName is interpreted as a URL, and may use any scheme supported by QQmlEngine, including qrc, file, and http. If the URL is invalid or the root object of the loaded component is not a Style, a warning is emitted and the constructed style behaves as QCommonStyle until a valid stylePath is set.

[override virtual noexcept] QStyleKitStyle::~QStyleKitStyle()

Destroys the QStyleKitStyle.

QStringList QStyleKitStyle::customThemeNames() const

Returns the names of the custom themes defined by the loaded Style, excluding the built-in Light and Dark themes. Returns an empty list when no style is loaded.

See also themeNames().

[override virtual] void QStyleKitStyle::drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w = nullptr) const

[override virtual] void QStyleKitStyle::drawControl(QStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const

[override virtual] void QStyleKitStyle::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const

[override virtual protected] bool QStyleKitStyle::eventFilter(QObject *obj, QEvent *event)

[override virtual] QStyle::SubControl QStyleKitStyle::hitTestComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *w = nullptr) const

[override virtual] int QStyleKitStyle::pixelMetric(QStyle::PixelMetric m, const QStyleOption *opt = nullptr, const QWidget *widget = nullptr) const

[override virtual] void QStyleKitStyle::polish(QApplication *app)

[override virtual] void QStyleKitStyle::polish(QPalette &palette)

[override virtual] void QStyleKitStyle::polish(QWidget *widget)

void QStyleKitStyle::setStylePath(const QString &fileName)

Loads the QML Style at fileName and applies it to all widgets.

fileName is interpreted as a URL. If the URL is the same as the currently loaded style, this function does nothing. If the new style cannot be loaded, the previously loaded style remains active and a warning is emitted; stylePathChanged() is still emitted to reflect the changed property value.

Note: Setter function for property stylePath.

See also stylePath().

void QStyleKitStyle::setThemeName(const QString &themeName)

Activates the theme named themeName.

themeName must be one of the entries in themeNames(), or the special name System to follow the platform color scheme. If no Style has been loaded, this function emits a warning and returns without changing the active theme.

Note: Setter function for property themeName.

See also themeName() and themeNames().

[override virtual] QSize QStyleKitStyle::sizeFromContents(QStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget = nullptr) const

[override virtual] QPalette QStyleKitStyle::standardPalette() const

[override virtual] int QStyleKitStyle::styleHint(QStyle::StyleHint sh, const QStyleOption *opt = nullptr, const QWidget *w = nullptr, QStyleHintReturn *shret = nullptr) const

QString QStyleKitStyle::stylePath() const

Returns the URL of the currently loaded Style file.

Note: Getter function for property stylePath.

See also setStylePath().

[override virtual] QRect QStyleKitStyle::subControlRect(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, QStyle::SubControl sc, const QWidget *w = nullptr) const

[override virtual] QRect QStyleKitStyle::subElementRect(QStyle::SubElement r, const QStyleOption *opt, const QWidget *widget = nullptr) const

QString QStyleKitStyle::themeName() const

Returns the name of the currently active theme, or an empty string if no Style has been loaded.

Note: Getter function for property themeName.

See also setThemeName() and themeNames().

QStringList QStyleKitStyle::themeNames() const

Returns the names of all themes exposed by the loaded Style, including the built-in Light and Dark themes and any custom themes defined by the style. Returns an empty list when no style is loaded.

Note: Getter function for property themeNames.

See also customThemeNames() and themeName().

[override virtual] void QStyleKitStyle::unpolish(QApplication *app)

[override virtual] void QStyleKitStyle::unpolish(QWidget *widget)

© 2026 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.