본문 바로가기

M E M O

Put Icon on Qt Tab Bar


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
81
82
#ifndef TESTTABBAR_H
#define TESTTABBAR_H
 
#include <QTabBar>
#include <QPainter>
#include <QStylePainter>
#include <QStyleOptionTab>
 
class TestTabBar : public QTabBar
{
    public:
        explicit TestTabBar(QWidget* parent=0) : QTabBar(parent)
        {
            //setIconSize(QSize(94,51));
        }
 
    protected:
        QSize tabSizeHint(intconst
        {
            return QSize(113,50);
        }
 
 
 
 
        void paintEvent(QPaintEvent *){
            QStylePainter p(this);
 
 
             for (int index = 0; index < count(); index++)
             {
                      QStyleOptionTabV3 tab;
                      initStyleOption(&tab, index);
 
 
                      QIcon tempIcon = tabIcon(index);
                      QString tempText = this->tabText(index);
 
                      QRect tabrect = tabRect(index);
 
                      tab.icon = QIcon();
                      tab.text = QString();
 
                      p.drawControl(QStyle::CE_TabBarTab, tab);
                      tabrect.adjust(0000);
 
                    //  p.setPen(Qt::black);
                    //  p.setFont(QFont("Arial", 7));
 
                      //p.drawText(tabrect, Qt::AlignBottom | Qt::AlignHCenter, tempText );
                      tempIcon.paint(&p, tabrect, Qt::AlignTop | Qt::AlignLeft);
 
                      this->setTabIcon(index, tempIcon );
                      this->setTabText( index, tempText);
 
 
              }
        }
};
 
class TestTabWidget : public QTabWidget
{
public:
 
    /**@brief TabWidget 에  연동하여 그리기  **/
    explicit TestTabWidget(QWidget *parent = 0) : QTabWidget(parent)
    {
        setTabBar(new TestTabBar());
    }
};
 
 
 
#endif // TESTTABBAR_H
 
 
 
void configure::CreateTabBar()
{
 
    // Use TabWidget, Make Tab
    TestTabWidget* test = new TestTabWidget(this);
     test->setGeometry(2020300200);
 
 
     test->addTab(new QWidget(), QIcon(":/res/Img.png"), "");
     test->addTab(new QWidget(), QIcon(":/res/Img2.png"), "");
     test->setTabPosition(QTabWidget::North);
 
 
}
 
 
cs


'M E M O' 카테고리의 다른 글

방명록 만듬 [Tirium 스킨]  (0) 2015.05.14
드디어 라이브코딩 인터뷰에 나오다!  (0) 2015.04.20
Put Icon on Qt Tab Bar  (0) 2015.03.16
+ 로그 기능 만들기 +  (0) 2014.07.18
고급 개발자에 대한 6가지 진실  (0) 2013.01.16
[프로그래머 격언]  (0) 2013.01.16