【问题标题】:How to uncheck a checked radio buttons in pyqt4如何取消选中pyqt4中选中的单选按钮
【发布时间】:2015-06-05 11:18:57
【问题描述】:

我正在做一个测验,按下下一个按钮后,我希望取消选中单选按钮,但这并没有发生。这是我放置单选按钮的地方。

self.answers = QtGui.QButtonGroup(self) 
self.Correctanswer = QRadioButton()
self.Incorrectans1 = QRadioButton()
self.Incorrectans2 = QRadioButton()
self.Incorrectans3 = QRadioButton()
self.answers.addButton(self.Correctanswer)
self.answers.addButton(self.Incorrectans1)
self.answers.addButton(self.Incorrectans2)
self.answers.addButton(self.Incorrectans3)
self.answers.buttonClicked.connect(self.QuestionCheck)
self.Correctanswer.setAutoExclusive(True)
self.Incorrectans1.setAutoExclusive(True)
self.Incorrectans2.setAutoExclusive(True)
self.Incorrectans3.setAutoExclusive(True)

这里是连接到我的下一个按钮的子程序。在这里,我尝试将单选按钮设置为清晰,但这并没有发生。单选按钮仍然具有上一个问题的先前选择。

def Showquestions2(self):
    self.Questionum.setText("Question 2")
    self.Correctanswer.setChecked(False)
    self.Incorrectans1.setChecked(False)
    self.Incorrectans2.setChecked(False)
    self.Incorrectans3.setChecked(False)
    self.ismultichoiceButton.clicked.connect(self.Showquestions3)

谁能告诉我我哪里出错了?谢谢

【问题讨论】:

  • 如果您更仔细地查看my answer 对您之前的问题之一,您会找到解决方案。
  • 哦,对了,谢谢我看到了。括号中的索引让我失望,所以我没有尝试。谢谢

标签: python pyqt pyqt4 qradiobutton


【解决方案1】:
def Showquestions2(self):
    self.group.setExclusive(False)
    self.Questionum.setText("Question 2")
    self.Correctanswer.setChecked(False)
    self.Incorrectans1.setChecked(False)
    self.Incorrectans2.setChecked(False)
    self.Incorrectans3.setChecked(False)
    self.ismultichoiceButton.clicked.connect(self.Showquestions3)
    self.group.setExclusive(True)

尝试此代码以进一步参考此link

【讨论】:

  • 感谢它的魅力,改变 self.group 的答案,它的工作。
  • 在 PyQt 5 中使用 QtWidget 而不是 QtGui
猜你喜欢
  • 2012-01-31
  • 2011-01-08
  • 2011-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-23
相关资源
最近更新 更多