-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabBar.h
More file actions
64 lines (57 loc) · 1.48 KB
/
TabBar.h
File metadata and controls
64 lines (57 loc) · 1.48 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
#ifndef TABBAR_H
#define TABBAR_H
#include <QTabBar>
#include <QStylePainter>
#include <QStyleOptionTabV3>
#include <QPainter>
#include <QIcon>
#include <QString>
class TabBar : public QTabBar
{
public:
explicit TabBar(QWidget* parent=0) : QTabBar(parent)
{
setIconSize(QSize(60, 60)); // 18 18
setStyleSheet("QTabBar { font: 9pt }");
}
protected:
QSize tabSizeHint(int) const
{
return QSize(125, 100); // 125 100
}
void wheelEvent(QWheelEvent *)
{
if ( this->hasFocus() )
return;
}
void paintEvent(QPaintEvent *)
{
QStylePainter p(this);
for (int index = 0; index < count(); index++)
{
QStyleOptionTabV3 tab;
initStyleOption(&tab, index);
QIcon tempIcon = tab.icon;
QString tempText = tab.text;
tab.icon = QIcon();
tab.text = QString();
p.drawControl(QStyle::CE_TabBarTab, tab);
QPainter painter;
painter.begin(this);
QRect tabrect = tabRect(index);
tabrect.adjust(0, 8, 0, -8);
painter.drawText(tabrect, Qt::AlignBottom | Qt::AlignHCenter, tempText);
tempIcon.paint(&painter, tabrect, Qt::AlignTop | Qt::AlignHCenter);
painter.end();
}
}
};
class TabWidget : public QTabWidget
{
public:
explicit TabWidget(QWidget *parent = 0) : QTabWidget(parent)
{
setTabBar(new TabBar());
}
};
#endif //TABBAR_H