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. Regarding how to find the children
QtWS25 Last Chance

Regarding how to find the children

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 3.9k Views
  • 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.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by
    #1

    Hi,

    i have a VBox and HBox layout, widgets are added to Hbox, later align using VBox,
    how can i find children.

    Code below:

    m_hbox->addWidget(addKeys(tr("Q"),characters));
       m_hbox->addWidget(addKeys(tr("W"),characters));
       m_hbox->addWidget(addKeys(tr("E"),characters));
       m_hbox->addWidget(addKeys(tr("R"),characters));
       m_hbox->addWidget(addKeys(tr("T"),characters));
       m_hbox->addWidget(addKeys(tr("Y"),characters));
       m_hbox->addWidget(addKeys(tr("U"),characters));
       m_hbox->addWidget(addKeys(tr("I"),characters));
       m_hbox->addWidget(addKeys(tr("O"),characters));
       m_hbox->addWidget(addKeys(tr("P"),characters));
       m_hbox->addWidget(addKeys("backspaceicon",backspace_icon));
    
       m_vbox->insertLayout(0,m_hbox);
    
    
       m_hbox1->addWidget(addKeys(tr("A"),characters));
       m_hbox1->addWidget(addKeys(tr("S"),characters));
       m_hbox1->addWidget(addKeys(tr("D"),characters));
       m_hbox1->addWidget(addKeys(tr("F"),characters));
       m_hbox1->addWidget(addKeys(tr("G"),characters));
       m_hbox1->addWidget(addKeys(tr("H"),characters));
       m_hbox1->addWidget(addKeys(tr("J"),characters));
       m_hbox1->addWidget(addKeys(tr("K"),characters));
       m_hbox1->addWidget(addKeys(tr("L"),characters));
       m_hbox1->addWidget(addKeys("entericon",enter_icon));
    
       m_vbox->insertLayout(1,m_hbox1);
    
    
       m_hbox2->addWidget(addKeys("capsicon",caps_icon));
       m_hbox2->addWidget(addKeys(tr("Z"),characters));
       m_hbox2->addWidget(addKeys(tr("X"),characters));
       m_hbox2->addWidget(addKeys(tr("C"),characters));
       m_hbox2->addWidget(addKeys(tr("V"),characters));
       m_hbox2->addWidget(addKeys(tr("B"),characters));
       m_hbox2->addWidget(addKeys(tr("N"),characters));
       m_hbox2->addWidget(addKeys(tr("M"),characters));
       m_hbox2->addWidget(addKeys(tr(","),characters));
       m_hbox2->addWidget(addKeys(tr("."),characters));
       m_hbox2->addWidget(addKeys("capsicon",caps_icon));
    
    
       m_vbox->insertLayout(2,m_hbox2);
    
    
       m_hbox3->addWidget(addKeys("&123",numbers));
       m_hbox3->addWidget(addKeys("multilingual",multilingual_icon));
       m_hbox3->addWidget(addKeys("spacebar",spacebar));
       m_hbox3->addWidget(addKeys(",",characters));
       m_hbox3->addWidget(addKeys(":-)",characters));
       m_hbox3->addWidget(addKeys("close",close_icon));
    
       m_vbox->insertLayout(3,m_hbox3);
    
    
       this->setLayout(m_vbox);
    

    how to find children ?.

    If i try to use below code, getting zero as list size.

    QVBoxLayout * layout = m_vbox->findChild<QVBoxLayout *> ();
      QList<QWidget *> list = layout->findChildren<QWidget *> ();
    
      qDebug() <<  "list size of children present :>" << list.size() << endl;
    

    Thanks,

    Pradeep Kumar
    Qt,QML Developer

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

      QLayout is a QObject, not a QWidget. the items you are searching for are not children of QLayout but of m_vbox directly

      QList<QWidget *> list = m_vbox->findChildren<QWidget *> ();

      "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
      1
      • Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on last edited by Pradeep Kumar
        #3

        used
        QList<QWidget *> list = m_vbox->findChildren<QWidget *> ();

        getting zero as list size.:(

        Thanks,

        Pradeep Kumar
        Qt,QML Developer

        Venkatesh VV 1 Reply Last reply
        0
        • Pradeep KumarP Pradeep Kumar

          used
          QList<QWidget *> list = m_vbox->findChildren<QWidget *> ();

          getting zero as list size.:(

          Thanks,

          Venkatesh VV Offline
          Venkatesh VV Offline
          Venkatesh V
          wrote on last edited by
          #4

          @Pradeep-Kumar
          Hi,

          If you want to get all the widgets inside the layout try this,

          QList<QWidget *> list;
          for (int i = 0; i < lyt->count(); ++i)
          {
          QWidget *widget = lyt->itemAt(i)->widget();
          if (widget != NULL)
          {
          list.append(widget);
          }
          }

          1 Reply Last reply
          1
          • Pradeep KumarP Offline
            Pradeep KumarP Offline
            Pradeep Kumar
            wrote on last edited by Pradeep Kumar
            #5

            Just want to know all the children present in Vbox.

            Thanks,

            Pradeep Kumar
            Qt,QML Developer

            Venkatesh VV 1 Reply Last reply
            0
            • Pradeep KumarP Pradeep Kumar

              Just want to know all the children present in Vbox.

              Thanks,

              Venkatesh VV Offline
              Venkatesh VV Offline
              Venkatesh V
              wrote on last edited by
              #6

              @Pradeep-Kumar said in Regarding how to find the children:

              Just want to know all the children present in Vbox.

              what do you mean?

              1 Reply Last reply
              1
              • Pradeep KumarP Offline
                Pradeep KumarP Offline
                Pradeep Kumar
                wrote on last edited by
                #7

                meaning i want to find children present in vbox. as i provided code above.

                Thanks,

                Pradeep Kumar
                Qt,QML Developer

                1 Reply Last reply
                0
                • Vinod KuntojiV Offline
                  Vinod KuntojiV Offline
                  Vinod Kuntoji
                  wrote on last edited by
                  #8

                  @Pradeep-Kumar ,

                  for(int i = 0; i < m_VBox->count(); i++) {
                      qDebug() << Q_FUNC_INFO << "No of child widgets: " << m_VBox->itemAt(i)->layout()->count() << endl;
                      int count = m_VBox->itemAt(i)->layout()->count();
                      for(int j = 0; j < count; j++) {
                          qDebug() << Q_FUNC_INFO << "Widget at:" << m_VBox->itemAt(i)->layout()->itemAt(j)->widget()->objectName() << endl;
                      }
                  }
                  

                  C++, Qt, Qt Quick Developer,
                  PthinkS, Bangalore

                  1 Reply Last reply
                  1
                  • Pradeep KumarP Offline
                    Pradeep KumarP Offline
                    Pradeep Kumar
                    wrote on last edited by
                    #9

                    Hi,

                    thanks all, it worked and i am getting the child present in the vbox layout.

                    Thanks,

                    Pradeep Kumar
                    Qt,QML Developer

                    1 Reply Last reply
                    0

                    • Login

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