Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt4 expanding tabs in QTabBar

I am subclassing QTabWidget to add a QTabBar, who's tabs stretch over the whole width of the tabBar. Therefore I am setting the expanding property to true. This doesn't seem to change anything about the behavior of the tabs.

Did anyone encounter the same problem? I use Qt 4.6 in combination with

TabWidget::TabWidget(QWidget *parent)
{
    tabBar = new QTabBar(this);
    tabBar->setIconSize(QSize(160,160));
    tabBar->setExpanding(true);
    setTabBar(tabBar);
}

EDIT: has been solved, here is how I implemented it, in case anyone is interested:

    tabBar = new QTabBar(this);
    tabBar->setExpanding(true);
    layout = new QVBoxLayout(this);
    setLayout(layout);
    stackedLayout = new QStackedLayout();
    layout->addWidget(tabBar);
    layout->addLayout(stackedLayout);
    connect(tabBar, SIGNAL(currentChanged(int)), stackedLayout, SLOT(setCurrentIndex(int)));

void MainWindow::addTab(QWidget *widget, const QIcon &icon, const QString &label) {
    tabBar->addTab(icon, label);
    stackedLayout->addWidget(widget);
}
like image 910
user636530 Avatar asked Feb 27 '11 14:02

user636530


2 Answers

From the QTabBar source code:

// ... Since we don't set
// a maximum size, tabs will EXPAND to fill up the empty space.
// Since tab widget is rather *ahem* strict about keeping the geometry of the
// tab bar to its absolute minimum, this won't bleed through, but will show up
// if you use tab bar on its own (a.k.a. not a bug, but a feature).

To get around this "feature", you can create your own tab widget using a QTabBar above a widget with a QStackedLayout.

like image 111
baysmith Avatar answered Oct 23 '22 21:10

baysmith


5.2.0 onwards

QTabWidget::tab-bar {
   min-width: 999999px;
}

It will work. No need to use any combination. You can use QTabWidget. Daniel ans is correct.

like image 29
Yash Avatar answered Oct 23 '22 21:10

Yash