How do I invoke a QCompleter's completion list on a specific keyboard shortcut? Rather than have completions shown after each character is typed, I would like the completions to show only after the user has pressed Shift+Return.

I have gotten to the point where I can enable/disable autocompletion, but doing so doesn't invoke the completion popup until the next character is pressed.

Current Behavior:
  1. User types the letter "c".
  2. User presses the Shift+Return keyboard shortcut.
  3. The use then types the letter "a".
  4. A popup box with the words "cat", "cattle", and "cave" appears.


Desired Behavior:
  1. User types the letter "c".
  2. User presses the Shift+Return keyboard shortcut.
  3. A popup box with the words "cat", "cattle", and "cave" appears.


In other words, the popup box shoudl appear immediately after the shortcut is pressed.

Here is the current (relevant) code:
Qt Code:
  1. ...
  2. class AutoCompleteFilter(QObject):
  3. def __init__(self):
  4. QObject.__init__(self)
  5. self.isActive = False
  6.  
  7. def eventFilter(self, object, event):
  8. if event.type() == QEvent.KeyPress:
  9. if event.modifiers() and Qt.ControlModifier:
  10. if event.key() == Qt.Key_Return:
  11. if self.isActive:
  12. self.isActive = False
  13. self.emit(SIGNAL("autoCompleteToggled(bool)"), False)
  14. else:
  15. self.isActive = True
  16. self.emit(SIGNAL("autoCompleteToggled(bool)"), True)
  17.  
  18. return True
  19.  
  20. return QObject.eventFilter(self, object, event)
  21. ...
  22. class DeckEditorWindow(QMainWindow, Ui_DeckEditorWindow):
  23.  
  24. def __init__(self, parent=None):
  25. ...
  26.  
  27. self.autoCompleteFilter = AutoCompleteFilter()
  28.  
  29. self.connect(self.autoCompleteFilter,
  30. SIGNAL("autoCompleteToggled(bool)"),
  31. self.autoComplete)
  32.  
  33. self.filtersLineEdit.installEventFilter(self.autoCompleteFilter)
  34. ...
  35. def autoComplete(self, isActive):
  36. if isActive:
  37. self.completer = QCompleter(self)
  38. self.completer.setModel(self.resultsModel)
  39. self.completer.setModelSorting(QCompleter.CaseInsensitivelySortedModel)
  40. if isActive:
  41. self.completer = QCompleter(self)
  42. self.completer.setModel(self.resultsModel) self.completer.setModelSorting(QCompleter.CaseInsensitivelySortedModel)
  43. self.completer.setCaseSensitivity(Qt.CaseInsensitive)
  44. self.completer.setCompletionRole(Qt.DisplayRole)
  45. self.filtersLineEdit.setCompleter(self.completer)
  46. self.completer.complete()
  47. else:
  48. self.filtersLineEdit.setCompleter(None)
  49. ...
To copy to clipboard, switch view to plain text mode 


I've tried messing with the complete() and popup().show() methods with mixed results. Any help is greatly appreciated.