QButtonGroup 没有使复选框独占

QButtonGroup not making checkboxes exclusive(QButtonGroup 没有使复选框独占)

本文介绍了QButtonGroup 没有使复选框独占的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 QGroupBox 制作一组排他性复选框(据我所知,默认情况下是排他性的),但是当我运行我的程序时,复选框不是排他性的,并且它们的行为正常.

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)

是不是我做错了什么?

推荐答案

这个问题是因为垃圾收集器从内存中移除了变量QButtonGroup,要解决这个问题你必须给这个对象传递一个父对象:

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)

这篇关于QButtonGroup 没有使复选框独占的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:QButtonGroup 没有使复选框独占

基础教程推荐