Tory Hoke

Essays, art, and comics of the unexpected

FOLLOW:

Generous Genius Programmer Shares Secrets of PyQt Multiple Autocomplete

More

Most Recent Posts

Day 1: An Overview

(Experience this as a TikTok.) “Play is the work of childhood.” – Jean Piaget “or children, play is serious learning.” – Mr. Rogers Adult learning is

Read More »

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!

WOOOOOOT.

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.

Share This:

Comics: Rare Words

Comics: Sneaky VFX

Comics: Pure Silliness