Search code examples
qtqt5qwidgetqtabwidgetqtabbar

QTabWidget - Horizontal Tabs (when TabPosition=West)


I have a QTabWidget, which has another QTabWidget in every tab. The main QTabWidget's tabPosition is set to West.

Is there an easy way to make the tabs horizontal without subclass the QTabWidget (to change paint-event etc.) ?


Solution

  • Try this way:

    QTabWidget *tabw = ui->tabWidget;
    tabw->setTabText(0, "");
    tabw->setTabText(1, "");
    QTabBar *tabbar = tabw->tabBar();
    
    QLabel *lbl1 = new QLabel();
    lbl1->setText("tab 1");
    tabbar->setTabButton(0, QTabBar::LeftSide, lbl1);
    
    QLabel *lbl2 = new QLabel();
    lbl2->setText("tab 2");
    tabbar->setTabButton(1, QTabBar::LeftSide, lbl2);
    

    and previewer:

    enter image description here

    But the tab is a little higer than the tabs' text.