PyQt4: List QCheckBox items in layout

24 views
Skip to first unread message

Erik Spellerberg

unread,
Apr 2, 2015, 4:14:09 AM4/2/15
to python_in...@googlegroups.com

Hey guys, I have a PyQt4 question for you. I have a layout containing only a bunch of checkboxes, and rather than querying the state of every one manually I want to loop over the items in the layout, then simply grab their label if they are active.

for i in xrange(self.qt_window.verticalLayout_cb.count()):
    box = self.qt_window.verticalLayout_cb.itemAt(i)
    print box

The problem here is that it's returning them as QWidgetItem, not QCheckBox so I can't work with them. Maybe I am going about this the wrong way?

Marcus Ottosson

unread,
Apr 2, 2015, 4:36:11 AM4/2/15
to python_in...@googlegroups.com

If you post a small, but complete example it would be easier to test things out; but off the top of my head, layouts wrap widgets in QLayoutItems which has a widget() method on it to retrieve the inner widget.

for i in xrange(self.qt_window.verticalLayout_cb.count()):
    box = self.qt_window.verticalLayout_cb.itemAt(i).widget()
    print box

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e004ba0f-c697-45e5-a81a-c4e4f1b92edb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Erik Spellerberg

unread,
Apr 2, 2015, 4:52:53 AM4/2/15
to python_in...@googlegroups.com
You are absolutely right, it was hiding right there in front of me. Thank you very much!
Reply all
Reply to author
Forward
0 new messages