1
votes

I'm looking to invert the tabs in Qt Designer.

That is I'm looking to change the tabs from the QTabWidget standard:

/--tab1--\/--tab2--\________________

to

\--tab1--/\--tab2--/************************

Where that tab goes into the content, rather than out of it.

Is there a simple way for me to do this? Maybe a setting of Qtabwidget or some way to edit the CSS to make this happen?

Thanks

1

1 Answers

1
votes

That task is not possible to do with qss, what you have to do is create your own QTabBar and overwrite the paintEvent () method, another problem is that the setTabBar method is private so you'll have to create a class that inherits from QTabWidget, if you want to use that class within Qt Designer you must promote it:

#ifndef TABWIDGET_H
#define TABWIDGET_H

#include <QStyleOptionTab>
#include <QStylePainter>
#include <QTabWidget>

class TabBar: public QTabBar
{
protected:
    void paintEvent(QPaintEvent */*event*/){

        QStylePainter painter(this);
        QStyleOptionTab opt;

        for(int i = 0;i < count();i++)
        {   
            initStyleOption(&opt,i);

            QPoint c = tabRect(i).center();
            painter.translate(c);
            painter.rotate(-180);
            painter.translate(-c);
            painter.drawControl(QStyle::CE_TabBarTabShape, opt);
            painter.resetTransform();

            painter.drawControl(QStyle::CE_TabBarTabLabel,opt);
        }
    }
};

class TabWidget : public QTabWidget
{
public:
    TabWidget(QWidget *parent=0):QTabWidget(parent){
        setTabBar(new TabBar);
        setTabShape(QTabWidget::Triangular);
    }
};

#endif // TABWIDGET_H

The complete example can be found in the following link.

enter image description here