QTabWidget size



  • Hello,

    I have a QTabWidget with only 3 tabs and I would like that those tabs take the space of the lenght of the widget: Now I have :

    TTT
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX

    And I would like

    xxxTxxxTxxxTxxx
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX

    I know that I could do this with stylesheets for a given qtabwidget size but I dont know how I could do that it fits automatically if the qtabwidget size changes.



  • Hi,

    after the tabwidget's stylesheet is loaded and applied you need to resize the tabbar in your code: I think you could do this in two ways, either by subclassing the QTabWidget and manipulate the tab bar inside(recommended) or as following:

    @ QTabBar tabBar = ui->tabWidget->findChild<QTabBar >(QLatin1String("qt_tabwidget_tabbar"));
    if(tabBar)
    {
    QPushButton
    button = new QPushButton();
    button->setFlat(true);
    button->setFixedWidth(200);
    button->setText(tabBar->tabText(0));
    tabBar->setTabText(0,"");
    tabBar->setTabButton(0, QTabBar::LeftSide,((QWidget
    )(button)));
    }@

    getting the tabbar in such way looks "unorthodox" but it works :)

    Cheers!



  • I wil try this out, thanks :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.