Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTabWidget not appearing when findChildren is called.
Forum Updated to NodeBB v4.3 + New Features

QTabWidget not appearing when findChildren is called.

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mar0029
    wrote on last edited by
    #1

    Hello!

    I am trying to find all of the children of a layout. One of these children is a QTabWidget. It does not appear when called. Code is as follows:

     MainWindow::buildFunction()
     {
          configTabArea = new QTabWidget;
          configMainVbox = new QVBoxLayout;
          myHbox = new QHBoxLayout;
          button = new QPushButton;
          ...work...
          myHbox->addWidget(button);
          configMainVbox->addWidget(configTabArea);
          configMainVbox->addLayout(myHbox);
     }
    
     MainWindow::actionFunction()
     {
          QList<QLayout*> layoutList = configMainVbox->findChildren<QLayout *>();
          // line above finds one layout, the QHBoxLayout
    
          QList<QTabWidget*> tabList = configMainVbox->findChildren<QTabWidget *>():
          //this line finds nothing. Same when using QWidget instead of QTabWidget
     }
    

    Any help would be greatly appreciated

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      Try

      MainWindow::buildFunction()
       {
            configTabArea = new QTabWidget(this);
      configTabArea->setObjectName("configTabArea"); //Set the name
            configMainVbox = new QVBoxLayout;
            myHbox = new QHBoxLayout;
            button = new QPushButton;
            ...work...
            myHbox->addWidget(button);
            configMainVbox->addWidget(configTabArea);
            configMainVbox->addLayout(myHbox);
       }
      
       MainWindow::actionFunction()
       {
            QList<QLayout*> layoutList = configMainVbox->findChildren<QLayout *>();
            // line above finds one layout, the QHBoxLayout
      
            QTabWidget* tabList = findChild<QTabWidget *>("configTabArea"):
            //Check that tabList is not null
       }
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mar0029
        wrote on last edited by
        #3

        Thank you for your reply!

        So I tried your suggestion and it returns a null QObject.

        I noticed you set the parent of QTabWidget to this. This is all taking place in a non-modal dialog configScreen so I tried explicitly setting that as the parent but it didn't seem to have any effect.

        mrjjM 1 Reply Last reply
        0
        • M mar0029

          Thank you for your reply!

          So I tried your suggestion and it returns a null QObject.

          I noticed you set the parent of QTabWidget to this. This is all taking place in a non-modal dialog configScreen so I tried explicitly setting that as the parent but it didn't seem to have any effect.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @mar0029 said:

          • This is all taking place in a non-modal dialog configScreen

          But you seems to try to find the QTabWidget* in the context of MainWindow ?
          If QTabWidget lives in dialog ,
          you cannot find it from context of mainwindow unless
          its dialog->findChild

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mar0029
            wrote on last edited by mar0029
            #5

            Thank you for your response!

            One correction on my part, everything takes place within a modal dialog and not a non-modal one.

            I think I may have miss spoke. I'm posting a more complete version of my code below, minus details on what happens in the window.

             void MainWindow::configApply()
             {
                 QList<QLayout*> layoutList = configMainVbox->findChildren<QLayout*>();
            
            qDebug() << "layoutList size " << layoutList.size();
            
            QTabWidget* tabWidget = configScreen->layout()->layout()->findChild<QTabWidget*>("configTabArea");
            
            if(tabWidget != NULL)
            {
                qDebug() << "is OK ";
            }
            else
                qDebug() << "NULL";
             }
            
             void MainWindow::configFunction()
             {
            configScreen = new QDialog;
            configScreen->setFixedSize(575,500);
            
            myHbox = new QHBoxLayout;
            
            tab0 = new QWidget;
            tab1 = new QWidget;
            tab2 = new QWidget;
            tab3 = new QWidget;
            
            sa0 = new QScrollArea;
            sa1 = new QScrollArea;
            sa2 = new QScrollArea;
            sa3 = new QScrollArea;
            
            vbox0 = new QVBoxLayout;
            vbox1 = new QVBoxLayout;
            vbox2 = new QVBoxLayout;
            vbox3 = new QVBoxLayout;
            
            configTabArea = new QTabWidget;
            configMainVbox = new QVBoxLayout;
            configTabArea->setObjectName("configTabArea");
             //
             //stuff is added to the QVBoxLayouts
             //
               vbox0->setSizeConstraint(QLayout::SetFixedSize); //important to keep scrolling active
            vbox1->setSizeConstraint(QLayout::SetFixedSize);
            vbox2->setSizeConstraint(QLayout::SetFixedSize);
            vbox3->setSizeConstraint(QLayout::SetFixedSize);
            
            tab0->setLayout(vbox0);
            sa0->setWidget(tab0);
            
            tab1->setLayout(vbox1);
            sa1->setWidget(tab1);
            
            tab2->setLayout(vbox2);
            sa2->setWidget(tab2);
            
            tab3->setLayout(vbox3);
            sa3->setWidget(tab3);
            
            QPushButton *configApplyButton = new QPushButton("Apply");
            QPushButton *configCancelButton = new QPushButton("Cancel");
            
            myHbox->addWidget(configApplyButton);
            myHbox->addWidget(configCancelButton);
            
            configTabArea->addTab(sa0, tr("file1"));
            configTabArea->addTab(sa1, tr("file2"));
            configTabArea->addTab(sa2, tr("file3"));
            configTabArea->addTab(sa3, tr("file4"));
            
            configMainVbox->addWidget(configTabArea);
            configMainVbox->addLayout(myHbox);
            
            connect(configApplyButton, SIGNAL(clicked(bool)), this, SLOT(configApply()));
            connect(configCancelButton, SIGNAL(clicked(bool)), configScreen, SLOT(accept()));
            
            configScreen->setLayout(configMainVbox);
            configScreen->setWindowTitle("Set your file's configurations");
            
            configScreen->setAttribute(Qt::WA_DeleteOnClose);
            configScreen->exec();
            }
            

            let me know what you think.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @mar0029 said:

              Hi
              Normally this is very easy so I wonder if something odd is going on :)

              can u try

              QList<QTabWidget*> AlltabWidgetslist = configScreen->findChildren<QTabWidget*>();

              qDebug << "num of tabs:" << AlltabWidgetslist.count();

              and see if it say 1

              M 1 Reply Last reply
              1
              • mrjjM mrjj

                @mar0029 said:

                Hi
                Normally this is very easy so I wonder if something odd is going on :)

                can u try

                QList<QTabWidget*> AlltabWidgetslist = configScreen->findChildren<QTabWidget*>();

                qDebug << "num of tabs:" << AlltabWidgetslist.count();

                and see if it say 1

                M Offline
                M Offline
                mar0029
                wrote on last edited by
                #7

                @mrjj
                Thank you very much. This started me on the right path.

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved