擅长:python、mysql、java
<p>您遇到的问题是基于这样一个事实:您使用的QButtonGroup被设置为独占的。如果您查看<a href="http://qt-project.org/doc/qt-4.8/qbuttongroup.html#exclusive-prop" rel="nofollow">documentation</a>,您将看到它声明了以下内容:</p>
<blockquote>
<p>the user cannot uncheck the currently checked button by clicking on it; instead, <strong>another button in the group must be clicked</strong></p>
</blockquote>
<p>我不知道你的应用程序的逻辑,但如果你使用一个独占按钮组,你将需要设置一个差异按钮被检查,或不使用一个独占组,并强制检查自己。在</p>
<p>下面是您所看到的一个小例子:</p>
<pre><code>import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
button1 = QtGui.QCheckBox('test 1')
group = QtGui.QButtonGroup()
group.setExclusive(True)
group.addButton(button1)
print button1.isChecked()
button1.toggle()
print button1.isChecked()
button1.toggle()
print button1.isChecked()
# toggle seems not to work, add a second button
button2 = QtGui.QCheckBox('test 2')
group.addButton(button2)
print button2.isChecked()
button2.toggle()
print button1.isChecked()
print button2.isChecked()
</code></pre>