从 PyQt4 中的另一个单选按钮禁用和启用单选按钮 Python

Disable and enable radiobuttons from another radiobutton in PyQt4 Python

我有 3 个单选按钮组,形式为是或否。如果第一个单选按钮是 "No",我想禁用最后两个单选按钮组,并在第一个单选按钮是 "Yes" 时启用它们。我可以默认启用或禁用,但从第一组切换 Yes/No 不会改变第二组和第三组的结果。

这是我的代码摘要:

self.yes_radioButtonGroup1 = QtGui.QRadioButton(self.centralwidget)      
self.yes_radioButtonGroup1.setObjectName(_fromUtf8("yes_radioButtonGroup1"))
self.no_radioButtonGroup1 = QtGui.QRadioButton(self.centralwidget)
self.no_radioButtonGroup1.setObjectName(_fromUtf8("no_radioButtonGroup1"))
self.radioButtonGroup1= QtGui.QButtonGroup(MainWindow)   
self.radioButtonGroup1.setObjectName(_fromUtf8("radioButtonGroup1"))
self.radioButtonGroup1.addButton(self.yes_radioButtonGroup1)
self.radioButtonGroup1.addButton(self.no_radioButtonGroup1)

self.yes_radioButtonGroup2 = QtGui.QRadioButton(self.centralwidget)      
self.yes_radioButtonGroup2.setObjectName(_fromUtf8("yes_radioButtonGroup2"))
self.no_radioButtonGroup2 = QtGui.QRadioButton(self.centralwidget)
self.no_radioButtonGroup2.setObjectName(_fromUtf8("no_radioButtonGroup2"))
self.radioButtonGroup2= QtGui.QButtonGroup(MainWindow)   
self.radioButtonGroup2.setObjectName(_fromUtf8("radioButtonGroup2"))
self.radioButtonGroup2.addButton(self.yes_radioButtonGroup1)
self.radioButtonGroup2.addButton(self.no_radioButtonGroup1)

self.yes_radioButtonGroup3 = QtGui.QRadioButton(self.centralwidget)      
self.yes_radioButtonGroup3.setObjectName(_fromUtf8("yes_radioButtonGroup3"))
self.no_radioButtonGroup3 = QtGui.QRadioButton(self.centralwidget)
self.no_radioButtonGroup3.setObjectName(_fromUtf8("no_radioButtonGroup3"))
self.radioButtonGroup3= QtGui.QButtonGroup(MainWindow)   
self.radioButtonGroup3.setObjectName(_fromUtf8("radioButtonGroup3"))
self.radioButtonGroup3.addButton(self.yes_radioButtonGroup3)
self.radioButtonGroup3.addButton(self.no_radioButtonGroup3)


if self.yes_radioButtonGroup1.isChecked() == True:
        self.yes_radioButtonGroup2.setEnabled(True)
        self.no_radioButtonGroup2.setEnabled(True)
        self.yes_radioButtonGroup3.setEnabled(True)
        self.no_radioButtonGroup3.setEnabled(True)

elif self.no_radioButtonGroup1.isChecked() == True:
        self.yes_radioButtonGroup2.setEnabled(False)
        self.no_radioButtonGroup2.setEnabled(False)
        self.yes_radioButtonGroup3.setEnabled(False)
        self.no_radioButtonGroup3.setEnabled(False)

我想知道是否有人知道如何在第一个单选按钮的值发生变化时动态启用或禁用最后两个单选按钮组?

由于这些按钮是独占的,足以监视其中之一,因此适当的信号是 toggled(),如果按钮被选中,则发送信息。

    self.yes_radioButtonGroup1 = QtGui.QRadioButton(self.centralwidget)      
    self.yes_radioButtonGroup1.setObjectName(_fromUtf8("yes_radioButtonGroup1"))
    self.no_radioButtonGroup1 = QtGui.QRadioButton(self.centralwidget)
    self.no_radioButtonGroup1.setObjectName(_fromUtf8("no_radioButtonGroup1"))
    self.radioButtonGroup1= QtGui.QButtonGroup(MainWindow)   
    self.radioButtonGroup1.setObjectName(_fromUtf8("radioButtonGroup1"))
    self.radioButtonGroup1.addButton(self.yes_radioButtonGroup1)
    self.radioButtonGroup1.addButton(self.no_radioButtonGroup1)

    self.yes_radioButtonGroup2 = QtGui.QRadioButton(self.centralwidget)      
    self.yes_radioButtonGroup2.setObjectName(_fromUtf8("yes_radioButtonGroup2"))
    self.no_radioButtonGroup2 = QtGui.QRadioButton(self.centralwidget)
    self.no_radioButtonGroup2.setObjectName(_fromUtf8("no_radioButtonGroup2"))
    self.radioButtonGroup2= QtGui.QButtonGroup(MainWindow)   
    self.radioButtonGroup2.setObjectName(_fromUtf8("radioButtonGroup2"))
    self.radioButtonGroup2.addButton(self.yes_radioButtonGroup1)
    self.radioButtonGroup2.addButton(self.no_radioButtonGroup1)

    self.yes_radioButtonGroup3 = QtGui.QRadioButton(self.centralwidget)      
    self.yes_radioButtonGroup3.setObjectName(_fromUtf8("yes_radioButtonGroup3"))
    self.no_radioButtonGroup3 = QtGui.QRadioButton(self.centralwidget)
    self.no_radioButtonGroup3.setObjectName(_fromUtf8("no_radioButtonGroup3"))
    self.radioButtonGroup3= QtGui.QButtonGroup(MainWindow)   
    self.radioButtonGroup3.setObjectName(_fromUtf8("radioButtonGroup3"))
    self.radioButtonGroup3.addButton(self.yes_radioButtonGroup3)
    self.radioButtonGroup3.addButton(self.no_radioButtonGroup3)

    self.yes_radioButtonGroup1.toggled(self.on_yes_checked)
    # set initial state
    self.on_yes_checked(self.yes_radioButtonGroup1.isChecked())

def on_yes_checked(self, checked):
    self.yes_radioButtonGroup2.setEnabled(checked)
    self.no_radioButtonGroup2.setEnabled(checked)
    self.yes_radioButtonGroup3.setEnabled(checked)
    self.no_radioButtonGroup3.setEnabled(checked)