Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将滑块连接到PyQt4中的函数?_Python_Pyqt - Fatal编程技术网

Python 如何将滑块连接到PyQt4中的函数?

Python 如何将滑块连接到PyQt4中的函数?,python,pyqt,Python,Pyqt,我正在尝试将滑块的值转换为函数,并在lineEdit小部件中显示此函数的值。 这是我的密码: class MyForma1(object): def AddWidgets1(self, Form): Form.setObjectName(_fromUtf8("Form")) Form.resize(579, 542) self.horizontalSlider = QtGui.QSlider(Form) self.horiz

我正在尝试将滑块的值转换为函数,并在lineEdit小部件中显示此函数的值。 这是我的密码:

class MyForma1(object):
    def AddWidgets1(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(579, 542)
        self.horizontalSlider = QtGui.QSlider(Form)
        self.horizontalSlider.setGeometry(QtCore.QRect(120, 380, 321, 31))
        self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal)
        self.horizontalSlider.setInvertedAppearance(False)
        self.horizontalSlider.setInvertedControls(False)
        self.horizontalSlider.setObjectName(_fromUtf8("horizontalSlider"))
        self.lineEdit = QtGui.QLineEdit(Form)
        self.lineEdit.setGeometry(QtCore.QRect(112, 280, 331, 20))
        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))

        self.retranslateUi(Form)
        QtCore.QObject.connect(self.horizontalSlider, QtCore.SIGNAL('valueChanged(int)'), Form.changeText)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Form", None))

class MyForma2(QtGui.QDialog, MyForma1):
    def __init__(self, z11=0):
        QtGui.QDialog.__init__(self)
        self.AddWidgets1(self)
        self.z = z11

    def myfunc1(self):
        self.z = self.horizontalSlider.value


    def changeText(self):
        self.myfunc1()
        self.lineEdit.setText(str(self.z))

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Forma = MyForma2()
    Forma.show()
    sys.exit(app.exec_())
我想检索滑块的值并将其分配给self.z,在这种情况下,我想知道我应该写什么来代替这个:
self.z=self.horizontalslaider.value

它应该是
self.horizontalslaider.value()
,因为
value
是可调用的。 但是,
QHorizontalSlider.valueChanged
信号也会发出滑块的值,因此您可以按如下方式更改
changeText
方法:

def changeText(self, value):
    self.z = value
    self.lineEdit.setText(str(self.z))

也考虑使用新的信号时隙机制: