문제

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 (i.e. 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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top