{
public:
{
}
protected:
QSize tabSizeHint
(int) const {
}
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
);
p.
drawControl(QStyle::CE_TabBarTab, tab
);
tabrect.adjust(0, 3, 0, -3);
p.setPen(Qt::black);
p.
setFont(QFont("Arial",
7));
tempIcon.paint(&p, tabrect, Qt::AlignTop);
p.drawText(tabrect, Qt::AlignBottom | Qt::AlignHCenter, tempText );
}
}
};
.....
WidgetListTabWidget::WidgetListTabWidget(WidgetList* parent)
{
//........
this->setTabBar(new TestTabBar());
//.........
}
class TestTabBar : public QTabBar
{
public:
explicit TestTabBar(QWidget* parent=0) : QTabBar(parent)
{
}
protected:
QSize tabSizeHint(int) const
{
return QSize(120, 20);
}
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(0, 3, 0, -3);
p.setPen(Qt::black);
p.setFont(QFont("Arial", 7));
tempIcon.paint(&p, tabrect, Qt::AlignTop);
p.drawText(tabrect, Qt::AlignBottom | Qt::AlignHCenter, tempText );
}
}
};
.....
WidgetListTabWidget::WidgetListTabWidget(WidgetList* parent)
: QTabWidget(parent)
{
//........
this->setTabBar(new TestTabBar());
this->setTabPosition(QTabWidget::West);
//.........
}
To copy to clipboard, switch view to plain text mode
Bookmarks