blob: f4f0ca11c2ccd6889151281c6d51ce51b5e6dd1b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QApplication>
#include <QtGui>
//! [0]
class MyStylePlugin : public QStylePlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "mystyleplugin.json")
public:
MyStylePlugin(QObject *parent = nullptr);
QStyle *create(const QString &key) override;
};
//! [0]
class RocketStyle : public QCommonStyle
{
public:
RocketStyle() {};
};
class StarBusterStyle : public QCommonStyle
{
public:
StarBusterStyle() {};
};
MyStylePlugin::MyStylePlugin(QObject *parent)
: QStylePlugin(parent)
{
}
QStringList MyStylePlugin::keys() const
{
return QStringList() << "Rocket" << "StarBuster";
}
//! [1]
QStyle *MyStylePlugin::create(const QString &key)
{
QString lcKey = key.toLower();
if (lcKey == "rocket") {
return new RocketStyle;
} else if (lcKey == "starbuster") {
return new StarBusterStyle;
}
return nullptr;
}
//! [1]
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyStylePlugin plugin;
return app.exec();
}
|