QStylePlugin Class

The QStylePlugin class provides an abstract base for custom QStyle 插件。 更多...

头: #include <QStylePlugin>
继承: QObject

公共函数

QStylePlugin (QObject * parent = 0)
~QStylePlugin ()

重实现公共函数

virtual QStyle * create (const QString & key ) = 0
virtual QStringList keys () const = 0

额外继承成员

详细描述

The QStylePlugin class provides an abstract base for custom QStyle 插件。

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

Writing a style plugin is achieved by subclassing this base class, reimplementing the pure virtual keys () 和 create () functions, and exporting the class using the Q_EXPORT_PLUGIN2 () macro. See 如何创建 Qt 插件 了解细节。

另请参阅 QStyleFactory and QStyle .

成员函数文档编制

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.

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 )

创建并返回 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;
}
					

另请参阅 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.

另请参阅 create ().