Important: Please read the Qt Code of Conduct -

Get all items from within groupbox of pyqt

  • 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)

  • Lifetime Qt Champion


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

  • @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:

  • @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 :]

  • @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.

Log in to reply