Dear Lazyweb,

I'm working on a personal PyQt4 project for my parents' office, and I need to
autocomplete an editable QComboBox.

I can't use a standard Qt model (I need to store python objects in it), so I
subclassed QAbstractTableModel.

Here it is, it's a fairly generic subclass of QAbstractTableModel, with
variable number of columns:

It might not be perfect, but it works, and it's all that matters at the moment
(since it's my first serious PyQt4 project). Oh, well, it worked until I tried
to use it with an editable QComboBox.

And here's the app code (for the full working code, insert the above class
right after the imports):

Now, try running it. It works well when I use a QStandardItemModel.

Then, try decommenting the part where I use my subclassed model: it just doesn't
work: clicking on any item makes the QComboBox not change its currentIndex,
and this only happens if the combobox is editable.

I suspect I'm forgetting to override some function in my model, but I don't know
what exactly to override, and Google didn't help me. This is also backed up by
the fact that the exact same behaviour shows up when, instead of a QComboBox, I
try to autocomplete on a QLineEdit.

So, dear readers: can anyone explain what is happening? Thanks in advance!

UPDATE: it turned out that the culprit was the following bit inside data():

Adding also Qt.EditRole to the list of possible choices fixed the bug. YAY!

Show more