QStylePlugin Class
The QStylePlugin class provides an abstract base for custom QStyle plugins. 更多...
头文件: | #include <QStylePlugin> |
qmake: | QT += widgets |
基类: | QObject |
公有函数
QStylePlugin(QObject *parent = Q_NULLPTR) | |
~QStylePlugin() | |
virtual QStyle * | create(const QString &key) = 0 |
- 32 个公有函数继承自 QObject
其他继承的成员
- 1 个属性继承自 QObject
- 1 个公有槽函数继承自 QObject
- 2 个信号继承自 QObject
- 1 个公有变量继承自 QObject
- 10 个静态公有成员继承自 QObject
- 9 个受保护的函数继承自 QObject
- 2 个受保护的变量继承自 QObject
详细描述
The QStylePlugin class provides an abstract base for custom QStyle plugins.
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); };
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.
参见 QStyleFactory and QStyle.
成员函数
QStylePlugin::QStylePlugin(QObject *parent = Q_NULLPTR)
Constructs a style plugin with the given parent.
Note that this constructor is invoked automatically by the moc generated code that exports the plugin, so there is no need for calling it explicitly.
QStylePlugin::~QStylePlugin()
Destroys the style plugin.
Note that Qt destroys a plugin automatically when it is no longer used, so there is no need for calling the destructor explicitly.
[pure virtual]
QStyle *QStylePlugin::create(const QString &key)
Creates and returns a QStyle object for the given style key. If a plugin cannot create a style, it should return 0 instead.
The style key is usually the class name of the required style. Note that the keys are case insensitive. For example:
QStyle *MyStylePlugin::create(const QString &key) { QString lcKey = key.toLower(); if (lcKey == "rocket") { return new RocketStyle; } else if (lcKey == "starbuster") { return new StarBusterStyle; } return 0; }