Hi Ben,
I have modified the signal emit statement like you said. even
though it is still not firing /calling "updateNames" slot in NameCompleter
. What i have to do now? please suggest me.
self.emit(QtCore.SIGNAL("signalTextChanged"),names,prefix)
QtCore.QObject.connect(nameEditor,QtCore.SIGNAL("signalTextChanged(list,str)"),completer.updateNames)
thank you.
On Thu, Sep 22, 2011 at 6:36 PM, Ben Breslauer <[email protected]> wrote:
> When calling emit, you don't specify the signature. So in
> LineEditCompleter.text_changed, you should call
>
> self.emit(QtCore.SIGNAL("signalTextChanged"),names,prefix)
>
> In addition, when using old-style signals, you don't need to explicitly
> define the signal using QtCore.Signal, Because when you call QObject.emit
> (or here, self.emit), it creates the signal dynamically.
>
> Hope that helps!
>
> Ben
>
> On Thu, Sep 22, 2011 at 6:47 PM, Ravi ..........! <[email protected]>wrote:
>
>> Hi,
>> even after changing the name of the Signal still i'm getting error.
>>
>> *"
>> self.emit(QtCore.SIGNAL("signalTextChanged(list,str)"),names,prefix)
>> TypeError: Unknown type used to emit a signal: list"*
>>
>> class LineEditCompleter(QtGui.QLineEdit):
>> #create custom signal
>> signalTextChanged=QtCore.Signal(list,str)
>> def __init__(self,parent=None):
>> QtGui.QLineEdit.__init__(self,parent)
>>
>> self.connect(self,QtCore.SIGNAL("textChanged(QString)"),self.text_changed)
>>
>> def text_changed(self,text):
>> print "from text_changed:",text
>> allText=unicode(text)
>> prefix=allText.split(",")[-1].strip()
>>
>> names=list()
>> for name in allText.split(","):
>> name=unicode(name).strip()
>> if name!="":
>> names.append(str(name))
>>
>>
>> self.emit(QtCore.SIGNAL("signalTextChanged(list,str)"),names,prefix)
>>
>> def complete_name(self,text):
>> cursor_pos=self.cursorPosition()
>> before_text=unicode(self.text())[:cursor_pos]
>> after_text=unicode(self.text())[cursor_pos:]
>> prefix_len=len(before_text.split(",")[-1].strip())
>> self.setText("%s%s,
>> %s"%(before_text[:cursor_pos-prefix_len],text,after_text))
>> self.setCursorPosition(cursor_pos-prefix_len+len(text)+2)
>>
>> class NameCompleter(QtGui.QCompleter):
>> def __init__(self,names=list(),parent=None):
>> QtGui.QCompleter.__init__(self,names,parent)
>> self.names=names
>>
>> def updateNames(self,names,completion_prefix):
>> print "from updateNames:",names,completion_prefix
>> _names=list()
>> for name in names:
>> if not self.names.__contains__(name):
>> _names.append(name)
>>
>> model=QtGui.QStringListModel(_names,self)
>> self.setModel(model)
>>
>> self.setCompletionPrefix(completion_prefix)
>> if completion_prefix.strip() !="":
>> self.complete()
>>
>>
>> def main():
>> app=QtGui.QApplication(sys.argv)
>> nameEditor=LineEditCompleter()
>> names=list()
>> names.append("ABC")
>> names.append("DEF")
>> names.append("AAAA")
>> completer=NameCompleter(names)
>> completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
>>
>> QtCore.QObject.connect(nameEditor,QtCore.SIGNAL("signalTextChanged(list,str)"),completer.updateNames)
>>
>> QtCore.QObject.connect(completer,QtCore.SIGNAL("activated(QString)"),nameEditor.complete_name)
>> completer.setWidget(nameEditor)
>> nameEditor.show()
>> sys.exit(app.exec_())
>>
>> if __name__=="__main__":
>> main()
>>
>> _______________________________________________
>> PySide mailing list
>> [email protected]
>> http://lists.pyside.org/listinfo/pyside
>>
>>
>
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside