stepchik
17th November 2011, 11:51
Hello Professionals! I have an issue with close button position while using QTabBar.
Let's look at picture. I would like to move close button to right corner. I try to play with stylesheet, but had fiasko.
7110
Code:
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(WidgetLis t* parent)
: QTabWidget(parent)
{
//........
this->setTabBar(new TestTabBar());
this->setTabPosition(QTabWidget::West);
//.........
}
Let's look at picture. I would like to move close button to right corner. I try to play with stylesheet, but had fiasko.
7110
Code:
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(WidgetLis t* parent)
: QTabWidget(parent)
{
//........
this->setTabBar(new TestTabBar());
this->setTabPosition(QTabWidget::West);
//.........
}