简体   繁体   English

PyQt4连接到信号“ textValueChanged()”

[英]PyQt4 connect to signal “textValueChanged()”

I have a app that uses PyQt4 for GUI. 我有一个将PyQt4用于GUI的应用程序。 But having some issues with connecting to signals. 但是在连接信号时存在一些问题。

I made a button like this 我做了一个像这样的按钮

    self.button=QtGui.QPushButton("Load File") 
    QObject.connect( self.button,   SIGNAL('clicked ()'),     self.clicked )

And it perfectly fires the following function: 它完美地触发了以下功能:

def clicked(self):

So in the same manner i made a input element. 所以我以同样的方式做了一个输入元素。 However the input element signal does not fire when i change the text. 但是,当我更改文本时,输入元素信号不会触发。

    self.filter=QtGui.QInputDialog() #Create the Input Dialog
    self.filter.setInputMode (self.filter.InputMode.TextInput ) #Change the input type to text
    self.filter.setOption(self.filter.InputDialogOption.NoButtons,True) #I don't need the buttons so i have removed them
    self.filter.setLabelText("Filter") #I change the label to "filter"
    self.connect(  self.filter,   QtCore.SIGNAL("textValueChanged()"),     self.filterUpdate ) #I connect to the signal textValueChanged() that should be fired when the text is changed and make it fire the filterUpdate() function

The following is never fired: 绝不会触发以下内容:

def filterUpdate(self):
    print "Hello"

This works here: 这在这里工作:

from PyQt4 import QtCore, QtGui

import sys

app = QtGui.QApplication(sys.argv)

def filterUpdate():
    print('!')

filter = QtGui.QInputDialog()
filter.setInputMode (filter.TextInput)
filter.setOption(filter.NoButtons, True)
filter.setLabelText("Filter")
filter.textValueChanged.connect(filterUpdate)

filter.show()

sys.exit(app.exec_())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM