<tfoot id='7mTWx'></tfoot>

  • <small id='7mTWx'></small><noframes id='7mTWx'>

        <legend id='7mTWx'><style id='7mTWx'><dir id='7mTWx'><q id='7mTWx'></q></dir></style></legend>
        • <bdo id='7mTWx'></bdo><ul id='7mTWx'></ul>

        <i id='7mTWx'><tr id='7mTWx'><dt id='7mTWx'><q id='7mTWx'><span id='7mTWx'><b id='7mTWx'><form id='7mTWx'><ins id='7mTWx'></ins><ul id='7mTWx'></ul><sub id='7mTWx'></sub></form><legend id='7mTWx'></legend><bdo id='7mTWx'><pre id='7mTWx'><center id='7mTWx'></center></pre></bdo></b><th id='7mTWx'></th></span></q></dt></tr></i><div id='7mTWx'><tfoot id='7mTWx'></tfoot><dl id='7mTWx'><fieldset id='7mTWx'></fieldset></dl></div>

        取消选中所有其他复选框的复选框

        时间:2023-08-06
          <bdo id='HFhfW'></bdo><ul id='HFhfW'></ul>
          <tfoot id='HFhfW'></tfoot>

        • <legend id='HFhfW'><style id='HFhfW'><dir id='HFhfW'><q id='HFhfW'></q></dir></style></legend>
            <tbody id='HFhfW'></tbody>
          1. <i id='HFhfW'><tr id='HFhfW'><dt id='HFhfW'><q id='HFhfW'><span id='HFhfW'><b id='HFhfW'><form id='HFhfW'><ins id='HFhfW'></ins><ul id='HFhfW'></ul><sub id='HFhfW'></sub></form><legend id='HFhfW'></legend><bdo id='HFhfW'><pre id='HFhfW'><center id='HFhfW'></center></pre></bdo></b><th id='HFhfW'></th></span></q></dt></tr></i><div id='HFhfW'><tfoot id='HFhfW'></tfoot><dl id='HFhfW'><fieldset id='HFhfW'></fieldset></dl></div>

                  <small id='HFhfW'></small><noframes id='HFhfW'>

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

                  问题描述

                  我正在尝试进行一些验证,例如:

                  I'm trying to put in some validation such that:

                  • 选中选择 A"选择 B" 时,会自动取消选中 未选择"
                  • 选中未选中"时,选择 A"选择 B" 都会自动取消选中
                  • When either "Select A" or "Select B" is checked, "None Selected" is automatically unchecked
                  • When "None Selected" is checked, both "Select A" and "Select B" are automatically unchecked

                  但是当我运行此代码时,单击任何复选框都会取消选中 所有 3 个复选框.

                  But when I run this code, clicking any checkbox will uncheck all the 3 checkboxes.

                  即窗口初始化时选中了"None Selected".但是当我点击 "Select A" 时,它会取消选中 "None Selected",这是有意的,但没有得到 "Select A"检查.

                  i.e. The window initializes with "None Selected" checked. But when I click "Select A", it unchecks "None Selected", which is intended, but "Select A" doesn't get checked.

                  我做错了什么?

                  import sys
                  import PyQt5
                  
                  class Test(QWidget):
                      def __init__(self):
                          super().__init__()
                          self.initUI()
                  
                      def initUI(self):
                          checkBoxNone = QCheckBox("None Selected")
                          checkBoxA    = QCheckBox("Select A")
                          checkBoxB    = QCheckBox("Select B")
                  
                          checkBoxNone.setChecked(True)
                          checkBoxNone.stateChanged.connect(lambda checked: (checkBoxA.setChecked(False), checkBoxB.setChecked(False)))
                          checkBoxA.stateChanged.connect(lambda checked: checkBoxNone.setChecked(False))
                          checkBoxB.stateChanged.connect(lambda checked: checkBoxNone.setChecked(False))
                  
                          grid = QGridLayout()
                  
                          grid.addWidget(checkBoxNone, 1, 0)
                          grid.addWidget(checkBoxA, 2, 0)
                          grid.addWidget(checkBoxB, 3, 0)
                  
                          self.setLayout(grid)
                          self.setWindowTitle('Test')
                          self.show()
                  
                  if __name__ == '__main__':
                      if not QApplication.instance():
                          app = QApplication(sys.argv)
                      else:
                          app = QApplication.instance()
                      ex = Test()
                      sys.exit(app.exec_())
                  

                  推荐答案

                  问题是因为根据您的要求,只有在某些 QCheckBox 被勾选但您不做的情况下才应该做那些选项该验证,为了能够正确处理它,创建一个插槽并知道发出信号的对象,sender() 方法:

                  The problem is caused because according to your requirements, you should only make those options if some QCheckBox is checked but you do not do that verification, to be able to handle it properly, create a slot and to know which object the signal was emited, the sender() method:

                  import sys
                  from PyQt5.QtWidgets import *
                  from PyQt5.QtCore import *
                  
                  class Test(QWidget):
                      def __init__(self):
                          super().__init__()
                          self.initUI()
                  
                      def initUI(self):
                          self.checkBoxNone = QCheckBox("None Selected")
                          self.checkBoxA    = QCheckBox("Select A")
                          self.checkBoxB    = QCheckBox("Select B")
                  
                          self.checkBoxNone.setChecked(True)
                          self.checkBoxNone.stateChanged.connect(self.onStateChange)
                          self.checkBoxA.stateChanged.connect(self.onStateChange)
                          self.checkBoxB.stateChanged.connect(self.onStateChange)
                  
                          grid = QGridLayout(self)
                  
                          grid.addWidget(self.checkBoxNone, 1, 0)
                          grid.addWidget(self.checkBoxA, 2, 0)
                          grid.addWidget(self.checkBoxB, 3, 0)
                          self.setWindowTitle('Test')
                          self.show()
                  
                      @pyqtSlot(int)
                      def onStateChange(self, state):
                          if state == Qt.Checked:
                              if self.sender() == self.checkBoxNone:
                                  self.checkBoxA.setChecked(False)
                                  self.checkBoxB.setChecked(False)
                              elif self.sender() in (self.checkBoxA, self.checkBoxB):
                                  self.checkBoxNone.setChecked(False)
                  

                  这篇关于取消选中所有其他复选框的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:给定一个 pyqtBoundSignal 如何确定插槽? 下一篇:我在哪里为 Qt 设计器的单个提升 QWidget 编写类

                  相关文章

                  最新文章

                  <i id='EBg7l'><tr id='EBg7l'><dt id='EBg7l'><q id='EBg7l'><span id='EBg7l'><b id='EBg7l'><form id='EBg7l'><ins id='EBg7l'></ins><ul id='EBg7l'></ul><sub id='EBg7l'></sub></form><legend id='EBg7l'></legend><bdo id='EBg7l'><pre id='EBg7l'><center id='EBg7l'></center></pre></bdo></b><th id='EBg7l'></th></span></q></dt></tr></i><div id='EBg7l'><tfoot id='EBg7l'></tfoot><dl id='EBg7l'><fieldset id='EBg7l'></fieldset></dl></div>
                    <bdo id='EBg7l'></bdo><ul id='EBg7l'></ul>

                    <legend id='EBg7l'><style id='EBg7l'><dir id='EBg7l'><q id='EBg7l'></q></dir></style></legend>
                    1. <small id='EBg7l'></small><noframes id='EBg7l'>

                      <tfoot id='EBg7l'></tfoot>