Dynamically add checkBoxes in PySide while being able to refer to them later

40 views
Skip to first unread message

Jakob Kousholt

unread,
Nov 19, 2018, 12:54:47 AM11/19/18
to python_inside_maya
Hi,

I am trying to add a bunch of buttons and UI elements based of a python list. My issue is that I would need to refer to them later to see if they are checked or unchecked. Usually I would assign the button to a variable and check that specific variable for the state of the checkbox like:

potatoCheckBox = QtWidgets.QCheckBox()
potatoCheckBox.checkState() 

But I am not sure how to get about it over a list. of course the code is not making any sense as you can't add two strings like that together to assign a variable - big mess, However I think it kinda shows how I would like to go about it. Using my list as a prefix for a lot of new attributes on my UI class.  

list = ['potato', 'tomato', 'poop']

for obj in list:
    obj + CheckBox = QtWidgets.QCheckBox()

potatoCheckBox.checkState()
tomatoCheckBox.checkState()  
poopCheckBox.checkState()  

Any pointers in the right direction would be much appreciated. Thank you.

Jake


Marcus Ottosson

unread,
Nov 19, 2018, 1:25:06 AM11/19/18
to python_in...@googlegroups.com

How about something like this?

list = ['potato', 'tomato', 'poop'
]
boxes = {}

for obj in list:
    boxes[obj] = QtWidgets.QCheckBox()

boxes["potato"].checkState()
boxes["tomato"].checkState()  
boxes["poop"].checkState()

--
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/CAEKd6bbuUefk%2Bt8rmVT4wt8CVhu6ZBmx6N6pTKQOE%3DOeg1LH1w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Justin Israel

unread,
Nov 19, 2018, 3:01:34 AM11/19/18
to python_in...@googlegroups.com
From what part of the world does this cuisine originate? 

Marcus Ottosson

unread,
Nov 19, 2018, 3:49:25 AM11/19/18
to python_in...@googlegroups.com
I think it's referred to as a "Wellington Stew"

Jakob Kousholt

unread,
Nov 20, 2018, 7:02:54 PM11/20/18
to python_inside_maya
Thanks, Marcus. Totally did the trick!

Yeah, I wouldn't encourage you to cook that... haha!


Jakob Kousholt - Freelance Creature Modeler and Concept Sculptor
jak...@gmail.com
www.jakejk.com


Reply all
Reply to author
Forward
0 new messages