[PyQt] QComboBox insert policy

David Boddie david at boddie.org.uk
Fri Apr 20 00:55:16 BST 2007


On Thursday 19 April 2007 12:53:08 +0200, Tina I wrote:

> I have a QComboBox (Qt4) where I want to insert items alphabetically.

[...]

> The problem is of course that the item is inserted at position 'select'
> and not where it fits in the alphabet. And from the documentation I can
> not find any insert methods that does not require the 'index'. Am I
> missing something?

QComboBox doesn't provide any support for sorting itself. You could either
sort the list in advance or, if you need the unsorted list elsewhere, you
could use some technique for inserting the items in the correct order.

If it doesn't seem like a wasteful operation, you could just sort a copy of
the list and insert that into the combo box. You could even create a
QStringList, sort it, and pass that into QComboBox::addItems().

David


More information about the PyQt mailing list