Search code examples
pythonqtcheckboxpysideqt-designer

List of checked boxes in Pyside?


I created a gui in qtdesigner that has many checkboxes: Screenshot http://imgq.tk/img/-2012-07-13%2013:55:07.png

and I would like to know if there is a way to list all the checked boxes using pyside. It would be even better if I could just get the text from each box. The boxes are in a grid layout.


Solution

  • Since you're in python, you should be able to introspect on the object and find all its members. But Qt makes this easy in general because of the parent-child relationship. You can query the form (the parent) for its children that are text boxes:

    # my python's a bit rusty, but hopefully this is close
    checkboxes = [x for x in form.children() where isinstance(x, QCheckBox)]
    

    See the findChildren() and children() methods.