-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabwidget.h
58 lines (50 loc) · 1.52 KB
/
tabwidget.h
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
#ifndef TABWIDGET_H
#define TABWIDGET_H
#include <QStyleOptionTab>
#include <QStylePainter>
#include <QTabWidget>
#include <QDebug>
class TabBar: public QTabBar
{
public:
TabBar(const QHash<QString, QColor> &colors, QWidget *parent=nullptr) : QTabBar(parent) {
mColors = colors;
}
protected:
void paintEvent(QPaintEvent */*event*/) {
qDebug() << "***";
QStylePainter painter(this);
QStyleOptionTab opt;
for(int i = 0; i < count(); i++) {
initStyleOption(&opt, i);
qDebug() << " ---> " << opt;
if(mColors.contains(opt.text)){
opt.palette.setColor(QPalette::Button, mColors[opt.text]);
}
painter.drawControl(QStyle::CE_TabBarTabShape, opt);
painter.drawControl(QStyle::CE_TabBarTabLabel, opt);
}
}
private:
QHash<QString, QColor> mColors;
};
class TabWidget : public QTabWidget {
public:
TabWidget(QWidget *parent = nullptr) : QTabWidget(parent){
// text - color
QHash <QString, QColor> dict;
dict["Plot 0"] = QColor("yellow");
dict["1"] = QColor("#87ceeb");
dict["2"] = QColor("#90EE90");
dict["3"] = QColor("pink");
dict["4"] = QColor("#800080");
dict["5"] = QColor("yellow");
dict["6"] = QColor("#87ceeb");
dict["7"] = QColor("#90EE90");
dict["8"] = QColor("pink");
dict["9"] = QColor("#800080");
qDebug() << dict;
setTabBar(new TabBar(dict));
}
};
#endif // TABWIDGET_H