Qt4在QTabBar中展开标签

use*_*530 6 qt qt4 qtabbar qt4.6 qtabwidget

我正在进行子类化QTabWidget以添加一个QTabBar,其标签在整个宽度上延伸tabBar.因此我将扩展属性设置为true.这似乎没有改变选项卡的行为.

有没有人遇到同样的问题?我使用Qt 4.6与

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

编辑:已经解决,这是我如何实现它,万一有人感兴趣:

    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);
}
Run Code Online (Sandbox Code Playgroud)

bay*_*ith 3

QTabBar源代码来看:

// ... 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).
Run Code Online (Sandbox Code Playgroud)

要解决此“功能”,您可以使用QTabBar带有QStackedLayout.