1

GUI に PyQt4 を使用するアプリがあります。しかし、信号への接続にいくつかの問題があります。

こんなボタンを作りました

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

そして、次の関数を完全に起動します。

def clicked(self):

同じように、入力要素を作成しました。ただし、テキストを変更しても入力要素信号は発生しません。

    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

以下は決して発火しません:

def filterUpdate(self):
    print "Hello"
4

1 に答える 1

1

これはここで機能します:

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_())
于 2013-05-01T15:52:32.947 に答える