PDA

View Full Version : QTabBar - Stop it from collapsing when no tabs are present



ComServant
8th January 2012, 21:32
I'm using a QTabBar widget. When the QTabBar has no more tabs in it, it collapses its height down to nothing until a new tab is added. How can I disable that?
I want it to stay at a uniform height regardless of whether there are no tabs in it, or multiple tabs.

I searched the documentation but can't find any info on it. I also tried to work around it by placing the QTabBar within a QWidget, and programmaticly assigning the QWidget's minimum and maximum heights to the QTabBar's height after it contains a tab and is shown, but it re-sized it too large.

Any suggestions?

ChrisW67
8th January 2012, 22:37
QWidget::SetMinimumHeight() as in line 10:


#include <QtGui>
#include <QDebug>

class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
QWidget *central = new QWidget(this);
QTabBar *tb = new QTabBar(this);
tb->setMinimumHeight(50);
QLabel *label1 = new QLabel("Label 1", this);
QLabel *label2 = new QLabel("Label 2", this);

QVBoxLayout *layout = new QVBoxLayout(central);
layout->addWidget(label1);
layout->addWidget(tb);
layout->addWidget(label2);

setStyleSheet("QTabBar { background: green; }"
"QLabel { background: red; }");

central->setLayout(layout);
setCentralWidget(central);
}
};

int main(int argc, char *argv[])
{
QApplication app(argc, argv);


MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"