EditingFinished signal gets emitted on every key press in QLineEdit when QCompleter is used (Qt 4.8 in PySide 1.1.0), not just when pressing enter or



  • Hi Everyone,

    I am trying to build a QLineEdit with a custom QCompleter. I need a custom QCompleter so I can hook up a more efficient search engine ... I mocked this up in the sample code below (res = ...) to reproduce the issue.

    The trouble here is that when the pop up completion list is refreshed (on entering the second character and every character after that) editingFinished is emitted.

    Everything else works just fine. So how do I prevent the extra editingFinished signals?

    This snippet is partially based on http://john.nachtimwald.com/2009/07/04/qcompleter-and-comma-separated-tags/

    @
    from PySide import QtGui
    from PySide.QtGui import QCompleter, QLineEdit, QApplication
    import sys

    class CustomCompleter(QCompleter):
    def init(self, parent):
    QCompleter.init(self, [], parent)

    def update(self, completion_prefix):
        res = [str(i) for i in range(100000)] 
        model = QtGui.QStringListModel(res)
        self.setModel(model)
        self.setCompletionPrefix(completion_prefix)
        if completion_prefix.strip() != '':
            self.complete()
    

    def printEditFin():
    print 'editFinished'

    def main():
    app = QApplication(sys.argv)
    editor = QLineEdit()
    completer = CustomCompleter(editor)
    editor.textChanged.connect(completer.update)
    completer.activated.connect(editor.setText)
    completer.setWidget(editor)
    editor.editingFinished.connect(printEditFin)
    editor.show()
    return app.exec_()

    if name == 'main':
    main()
    @

    Thanks!

    Patrick



  • I might add it's line 15
    @
    self.complete()
    @

    that triggers the emission of the editingFinished signal.

    While I can hack around it - it's ugly - is there a better way?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.