Qt 4.5 (PyQt 4.6.1)
I'm looking for a widget similar to a QComboBox
that automatically filters its entries to the ones starting with the input in the text field. There are around 300 items in the combo box.
I've tried two approaches:
QLineEdit
with QCompleter
Advantages
- Filtering the items works.
Disadvantages
- Doesn't show a popup if the text field is empty.
- Doesn't do inline completion.
- Allows to insert items not in the list.
Editable QComboBox
with insertion set to no
Advantages
- Nice popup
- Completes inline in the text field.
Disadvantages
- No filtering
- Input is only possible in either the text field or the popup. Clicking on the popup doesn't select the best-matching item in the popup.
What I need
- A popup to select the items.
- Slow tippers should be able to start tipping the name of an item and the popup switches to the best matching one.
- Preferably I should filter the items so that only partially-matching items are shown.
Concerning you first try with QLineEdit, you can set the
completionMode
to do it inline.For your second try, you can add a QCompleter object to you QCombBox in order to filter your items as you want.The QCompleter member of the QComboBox is to offer an easy way to use QCompleter.
Anyway, if you are not satisfied with this method, you can manage a
QCompleter
object by yourself. This allows you to choose how item list is display (using any views) and to define items order in the list. See basic QCompleter details.