问题
I am attempting to make a set of exclusive checkboxes, using QGroupBox (which, as I understand it, is exclusive by default), but when I run my program, the checkboxes are not exclusive and behave as they normally would.
skillP = QCheckBox("Passive")
skillCb = QCheckBox("Combat")
skillCm = QCheckBox("Command")
skillP.setChecked(True)
addskillG = QButtonGroup()
addskillG.addButton(skillP)
addskillG.addButton(skillCm)
addskillG.addButton(skillCb)
Is there anything I'm doing wrong?
回答1:
The problem is caused because the garbage collector removes from the memory the variable QButtonGroup, to solve that problems you must pass a parent to this object:
addskillG = QButtonGroup(self)
来源:https://stackoverflow.com/questions/45384354/qbuttongroup-not-making-checkboxes-exclusive