我将QTabWidget子类化,以添加QTabBar,后者的选项卡在tabBar的整个宽度上延伸。因此,我将Expanding属性设置为true。这似乎并没有改变选项卡的行为。

有人遇到过同样的问题吗?我将Qt 4.6与

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

编辑:已解决,这是我的实现方式,以防万一有人感兴趣:
    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);
}

最佳答案

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).

要解决此“功能”,您可以在带有QTabBar的小部件上方使用QStackedLayout创建自己的标签小部件。

关于QTabBar中的Qt4扩展选项卡,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5133846/

10-11 21:27