views:

335

answers:

1

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.
+1  A: 

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.

Patrice Bernassola
1: By setting `completionMode` to inline I disable the popup. This is very bad. I've got many items like these: bread 300g, bread 700g, bread 1kg.
Georg
2: Doesn't the `QComboBox` already use a completer in inline mode?
Georg
3: Subclassing `QCompleter` sounds pretty good. I've already tried with subclassing `QValidator` and `QComboBox`.
Georg
1: Standard QCompleter only allows to choose between inline, popup OR unfiltered2: Yes that's what I would highlight to you since you have not mentionned you use it3: You can try this but I would subclassing QComboBox and redefine QCompleter behaviour
Patrice Bernassola