Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. 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
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pezzi
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pezzi
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved