QButtonGroup not making checkboxes exclusive

2019-07-26 22:55发布

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条回答
小情绪 Triste *
2楼-- · 2019-07-26 23:07

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)
查看更多
登录 后发表回答