2

QTabWidget当我知道活动选项卡索引和选项卡计数时,如何关闭所有选项卡但处于活动状态?关闭所有标签的功能是tabwidget->clear();

4

2 回答 2

2

你试过这个吗?

// remove all tabs after current
for (int i = tabWidget.count() - 1; i > tabWidget.currentIndex(); --i) {
   tabWidget.removeTab(i);
}

// current tab is now the last, therefore remove all but the last
for (int i = tabWidget.count(); i > 1; --i) {
   tabWidget.removeTab(0);
}
于 2012-10-14T16:49:40.293 回答
0

工作解决方案,这个来自的类继承了QTabWidget:

void closeOtherTabsRequested(int index)
{
    auto selectedWidget = widget(index);
    auto tabCount = mTabBar->count();
    for(auto i = tabCount - 1; i >= 0; i--) {
        auto currentWidget = widget(i);
        if(currentWidget != selectedWidget) {
            tabCloseRequested(i);
        }
    }
}
于 2020-05-19T21:58:13.543 回答