Generous Genius Programmer Shares Secrets of PyQt Multiple Autocomplete

It so happens I was looking for a way to do multiple autocompletes in a QComboBox.

In other words, I had an editable combo box containing the list:
– cupcake
– muffin
– pie

I wanted the user to be able to type “p” and have it autocomplete to “pie.”
This is no problem. Qt makes this automatic and wonderful, and it is a reason I want to give Qt a hug sometimes.

But then I want the user to keep typing “pie c” and have the combo box autocomplete “pie cupcake.”

This is a bit trickier.

I had seen some code for doing one’s own autocompletion combo box from scratch, and let us just say I did not want to write any.

So I sniffed around and found John Schember’s post about QCompleter and autocompleting multiple entries, and I was saved!


Fortunately, a QComboBox contains a QLineEdit object, so I was able to adapt this code while being very very lazy.

Woot. Thank you, John Schember.

(235 visits, 1 today)