Search code examples
c++cqtqt4

How to close all tabs but active in Qt4(QTabWidget)


How to close all tabs but active in QTabWidget, when i know a active tab index, and counts of tabs? The function of closing all tabs is tabwidget->clear();


Solution

  • Have you tried this?

    // 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);
    }