3

How to create autocomplete combobox in PyQt4?

Example what I want:

http://jqueryui.com/autocomplete/#combobox

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
user7172
  • 874
  • 4
  • 16
  • 31

2 Answers2

6

To get the same behaviour as in the example, you will need to change the completion mode of the completer for the combobox.

By default, the completion mode is inline (i.e. just selected text, with no alternatives). To get the drop-down list of possible alternatives, do:

    combobox.completer().setCompletionMode(QtGui.QCompleter.PopupCompletion)
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • I realize this is an old post. Is there a way to also add the ability for this to allow you to select MULTIPLE choices? – Ryan Glenn Jul 29 '22 at 19:42
  • @RyanGlenn Please ask a new question, since your request seems totally unrelated to the original question (and I'm not even sure what you mean). – ekhumoro Jul 29 '22 at 19:53
5

combobox.setEditable(True) combobox.completer().setCompletionMode(QtGui.QCompleter.PopupCompletion) combobox.setInsertPolicy(QComboBox.NoInsert)

First line : autocompletion is only available for an editable combobox.

Second line : sets required behavior for autocomplete method

Last line : prevents the user to add items to the list (to better match the example behavior you provided)

TheSpaceSheep
  • 51
  • 1
  • 3