QButtonGroup not making checkboxes exclusive

我的未来我决定 提交于 2019-12-11 07:03:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!