QStylePlugin Class

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

Header: #include <QStylePlugin>
Inherits: QObject

Public Functions

QStylePlugin(QObject * parent = 0)

Reimplemented Public Functions

virtual QStyle * create(const QString & key) = 0
virtual QStringList keys() const = 0
  • 29 public functions inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 1 signal inherited from QObject
  • 7 static public members inherited from QObject
  • 8 protected functions inherited from QObject

Detailed Description

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 keys() and create() functions, and exporting the class using the Q_EXPORT_PLUGIN2() macro. See How to Create Qt Plugins for details.

See also QStyleFactory and QStyle.

Member Function Documentation

QStylePlugin::QStylePlugin(QObject * parent = 0)

Constructs a style plugin with the given parent.

Note that this constructor is invoked automatically by the Q_EXPORT_PLUGIN2() macro, so there is no need for calling it explicitly.


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:

QStringList MyStylePlugin::keys() const
    return QStringList() << "Rocket" << "StarBuster";

QStyle *MyStylePlugin::create(const QString &key)
    QString lcKey = key;
    if (lcKey == "rocket") {
        return new RocketStyle;
    } else if (lcKey == "starbuster") {
        return new StarBusterStyle;
    return 0;

See also keys().

[pure virtual] QStringList QStylePlugin::keys() const

Returns the list of style keys this plugin supports.

These keys are usually the class names of the custom styles that are implemented in the plugin.

See also create().

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