Important: Please read the Qt Code of Conduct -

Catch TabWidget in active subwindows

  • I want to catch a qtabwidget in a subactivewindows but the problem is that when I use activeSubWindow().widget I don't have setcurrentindex in order to set one tab active(setfont).
    what's the problem?

    /*QMdiArea container*/
    test = new QMdiArea;

    stat2 = new QMdiSubWindow;

        onglets2 = new QTabWidget();
        onglets2->setGeometry(30, 20, 240, 160);
        // 2 : Créer les pages, en utilisant un widget parent pour contenir chacune des pages
        QWidget *page10 = new QWidget;
        QWidget *page20 = new QWidget;
        QLabel *page30 = new QLabel; // Comme un QLabel est aussi un QWidget (il en hérite), on peut aussi s'en servir de page
        onglets2->addTab(page10, "Graphe Traffic IPv4");
        onglets2->addTab(page20, "Stats");
        onglets2->addTab(page30, "Info-app");

    void MainWindow::toTab1()
    /catch active ongles(QtabWidget) and set Index to 1/
    onglets2 = test->activeSubWindow(). ----> setcurrentindex<---- ???

  • Lifetime Qt Champion

    You will need to cast it to the right type since it returns the base class (Qwidget)
    QTabWidget * tn = qobject_cast<QTabWidget *>( test->activeSubWindow()->widget())
    if (tn) { // this check is critical. the cast can fail if not a tabwidget
    use it

Log in to reply