pyQt: radioButton.isChecked() is executed twice

后端 未结 1 1998
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-19 19:13

I have this simple window (design.py) derived from Qt designer, which consists of three radio buttons:

# -*- coding: utf-8 -*-

from PyQt4 import Qt         


        
1条回答
  •  自闭症患者
    2020-12-19 20:03

    The toggle() signal is emitted every time any radio button's state changes. As a result, the toggle() signal is emitted when you click on a radio button and that radio button's state changes from unchecked to checked, and if clicking on the radio button automatically unchecks another radio button, then the toggle() signal is emitted again because the other radio button's state changes from checked to unchecked.

    You can see that in action by adding the following line to the end of your slot:

    print self.sender().text() + ' was toggled'
    

    Use the clicked() signal instead--a radio button whose state was automatically changed from checked to unchecked was never clicked.

    0 讨论(0)
提交回复
热议问题