切换本地QWidgets的可见性

时间:2018-01-19 19:56:50

标签: python pyqt pyqt4

我有一个模态QDialog,其中有几个小部件以网格布局排列。它有一个单选按钮组,如果按下某个按钮,它应切换某些小部件的可见性。此QDialog在本地声明。我通过连接的buttonClicked()函数访问小部件时遇到问题。有没有办法在不将所有小部件传递给函数或使它们成为基类的一部分的情况下实现这一目标?

def optionsdlg(self):               
    self.oWin = QDialog()
    self.oWin.setModal(True)
    self.oWin.setWindowTitle("Options")

    layout = QGridLayout()

    Button1 = QtGui.QRadioButton("Button1")
    Button2 = QtGui.QRadioButton("Button2")
    Button3 = QtGui.QRadioButton("Button3")
    lcbg = QtGui.QButtonGroup()
    lcbg.addButton(Button1, 0)
    lcbg.addButton(Button2, 1)
    lcbg.addButton(Button3, 2)
    lcbg.buttonClicked.connect(updateType(lcbg.checkedId()))
    scalingLabel = QtGui.QLabel("Scaling:")
    scalingLabel.setVisible(False)                              
    scalingLineEdit = QtGui.QLineEdit(str(self.scaling))
    scalingLineEdit.setVisible(False)
    offsetLabel = QtGui.QLabel("Offset:")
    offsetLabel.setVisible(False)
    offsetLineEdit = QtGui.QLineEdit(str(self.offset))
    offsetLineEdit.setVisible(False)

    self.oWin.setLayout(layout)

    self.oWin.exec_()

    def updateType(button):            
        if button == 0:
        elif button == 1:
        elif button == 2:
            scalingLabel.setVisible(True)
            scalingLineEdit.setVisible(True)
            offsetLabel.setVisible(True)
            offsetLineEdit.setVisible(True)

0 个答案:

没有答案