-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (66 loc) · 1.79 KB
/
main.cpp
File metadata and controls
80 lines (66 loc) · 1.79 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "mainwindow.h"
#include <QApplication>
#include <QMainWindow>
#include <QStyleFactory>
#include <QProxyStyle>
#include <QStringListModel>
#include <QComboBox>
#include <QLabel>
#include <QToolBar>
#include "customstyle.h"
/*!
* \brief main
* \param argc
* \param argv
* \return
* \see
* CustomStyle, MainWindow
*/
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QApplication::setStyle(new CustomStyle());
MainWindow w;
QMainWindow settingsWindow;
/*!
* \brief c 用于切换主题
*/
QComboBox c;
QStringList styles = QStyleFactory::keys();
styles.prepend("自定义");
QStringListModel model(styles);
c.setModel(&model);
/*!
* \brief c2 用于改变CustomStyle的proxy
*/
QComboBox c2;
QStringList styles2 = QStyleFactory::keys();
QStringListModel model2(styles2);
c2.setModel(&model2);
c2.setCurrentText("Windows");
c.connect(&c, QOverload<int>::of(&QComboBox::currentIndexChanged), [&](int index){
if (index == 0) {
QApplication::setStyle(new CustomStyle());
c2.setEnabled(true);
} else {
QApplication::setStyle(model.index(index).data().toString());
c2.setEnabled(false);
}
});
c2.connect(&c2, QOverload<int>::of(&QComboBox::currentIndexChanged), [&](int index){
if (c.currentText() == "自定义") {
QApplication::setStyle(new CustomStyle(model2.index(index).data().toString()));
}
});
QToolBar t;
QLabel l("选择样式:");
t.addWidget(&l);
t.addWidget(&c);
QLabel l2("CustomStyle继承自:");
t.addWidget(&l2);
t.addWidget(&c2);
settingsWindow.addToolBar(&t);
settingsWindow.setCentralWidget(&w);
settingsWindow.show();
return a.exec();
}