本文介紹了QButtonGroup 沒有使復(fù)選框獨(dú)占的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問題描述
我正在嘗試使用 QGroupBox 制作一組排他性復(fù)選框(據(jù)我所知,默認(rèn)情況下是排他性的),但是當(dāng)我運(yùn)行我的程序時(shí),復(fù)選框不是排他性的,并且它們的行為正常.
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)
是不是我做錯(cuò)了什么?
推薦答案
這個(gè)問題是因?yàn)槔占鲝膬?nèi)存中移除了變量QButtonGroup,要解決這個(gè)問題你必須給這個(gè)對(duì)象傳遞一個(gè)父對(duì)象:
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)
這篇關(guān)于QButtonGroup 沒有使復(fù)選框獨(dú)占的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!