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. Get all items from within groupbox of pyqt
Forum Updated to NodeBB v4.3 + New Features

Get all items from within groupbox of pyqt

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.5k 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.
  • P Offline
    P Offline
    poordev123
    wrote on last edited by poordev123
    #1

    I have a groupbox that has 4 comboboxes within it. I want to say in my code something along the lines of

    for i in self.ui.all_of_the_combo_boxes:
        do something
    

    I am aware of the .getChildren() method, but my problem with that is that I have about 6 other comboboxes throughout my gui. So I would be gettingback 10-12 values when I only need 4. On top of that it returns the comboboxes as

    [<PySide2.QtWidgets.QComboBox(0xfcbfad0, name="comb_pow_m") at 0x10C8F268>,
    

    rather than just the values.

    Or if there is just a way to get all the text of the items. For example something like

            children = self.findChildren(QComboBox)
            print(children.currentText())
    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can call findChildren on the combo box you are interested in.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • P poordev123

        I have a groupbox that has 4 comboboxes within it. I want to say in my code something along the lines of

        for i in self.ui.all_of_the_combo_boxes:
            do something
        

        I am aware of the .getChildren() method, but my problem with that is that I have about 6 other comboboxes throughout my gui. So I would be gettingback 10-12 values when I only need 4. On top of that it returns the comboboxes as

        [<PySide2.QtWidgets.QComboBox(0xfcbfad0, name="comb_pow_m") at 0x10C8F268>,
        

        rather than just the values.

        Or if there is just a way to get all the text of the items. For example something like

                children = self.findChildren(QComboBox)
                print(children.currentText())
        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #3

        @poordev123

        I have a groupbox that has 4 comboboxes within it.

        If I understand you right, it is from a groupbox (QGroupBox) that you want to find child comboboxes? Assuming so, depending on what your self is, you should be going:

                childCombos = self.someGroupBox.findChildren(QComboBox)
                for childCombo in childCombos:
                    print(childCombo.currentText())
        
        P 1 Reply Last reply
        2
        • JonBJ JonB

          @poordev123

          I have a groupbox that has 4 comboboxes within it.

          If I understand you right, it is from a groupbox (QGroupBox) that you want to find child comboboxes? Assuming so, depending on what your self is, you should be going:

                  childCombos = self.someGroupBox.findChildren(QComboBox)
                  for childCombo in childCombos:
                      print(childCombo.currentText())
          
          P Offline
          P Offline
          poordev123
          wrote on last edited by poordev123
          #4

          @JonB @SGaist That was exactly what I was looking for. I wasn't aware I could call findChildren on specific groupboxes, thank you very much :]

          JonBJ 1 Reply Last reply
          1
          • P poordev123

            @JonB @SGaist That was exactly what I was looking for. I wasn't aware I could call findChildren on specific groupboxes, thank you very much :]

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @poordev123
            Just so you know: it's QObject::findChildren() so you can actually call it on any QObject, and that includes any and all QWidgets. QGroupBox is a QWidget itself, and there are other such "container" widgets for which this works.

            1 Reply Last reply
            2

            • Login

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