QStylePlugin Class

The QStylePlugin class provides an abstract base for custom QStyle plugins. More...

Header: #include <QStylePlugin>
qmake: QT += widgets
Inherits: QObject

Detailed Description

QStylePlugin is a simple plugin interface that makes it easy to create custom styles that can be loaded dynamically into applications using the QStyleFactory class.

Writing a style plugin is achieved by subclassing this base class, reimplementing the pure virtual create() function, and exporting the class using the Q_PLUGIN_METADATA() macro.

 class MyStylePlugin : public QStylePlugin
 {
     Q_OBJECT
     Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "mystyleplugin.json")
 public:
     MyStylePlugin(QObject *parent = 0);

     QStyle *create(const QString &key) override;
 };

The json metadata file mystyleplugin.json for the plugin needs to contain information about the names of the styles the plugins supports as follows:

 { "Keys": [ "Rocket", "Starbuster" ] }

See How to Create Qt Plugins for details.

See also QStyleFactory and QStyle.