简体   繁体   中英

How to create autocomplete combobox in PyQt4?

How to create autocomplete combobox in PyQt4?

Example what I want:

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

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 (ie just selected text, with no alternatives). To get the drop-down list of possible alternatives, do:

    combobox.completer().setCompletionMode(QtGui.QCompleter.PopupCompletion)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM