当我知道有效的标签索引和标签数量时,如何关闭所有标签但在QTabWidget
中处于活动状态?
关闭所有标签的功能是tabwidget->clear();
答案 0 :(得分: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);
}
答案 1 :(得分: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);
}
}
}