Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to get the page in QTabWidget



  • I have below code
    QTabWidget* TabWidget = new QTabWidget(this);

    I am adding tabs with below code I have some QWidget user define class name like WigetTreeView;

    WidgetTreeView *tab1 = new WidgetTreeView(this);
    now I am adding this tab using below code.

    TabWidget ->addTab(tab1 , "Tab1");

    Now I need to get the the index of tab using tab name "Tab1" from TabWidget .

    How Can I do that?

    I tried findchildren<> method but it did not work for me.
    indexof() of QTabWidget always return -1;



  • Just iterate.

    for(int i=0;i<tabWidget->count();++i){
    if(tabWidget->tabText(i) == QStringLiteral("Tab1"))
    qDebug("Bingo!");
    }
    


  • Just iterate.

    for(int i=0;i<tabWidget->count();++i){
    if(tabWidget->tabText(i) == QStringLiteral("Tab1"))
    qDebug("Bingo!");
    }
    

Log in to reply