[PyKDE] QComboBox question...

Tom Van den Brandt tom.vandenbrandt at pi.be
Wed Nov 5 15:44:01 GMT 2003

Trevor Phillips wrote:

> GuineaPig wrote:
>> I'm new to pyqt and I'm having a question about QComboBox.  I have 
>> one on a form that I would like to populate with data from a 
>> db-table.  The table is very simple, it has only two columns, an id 
>> and a description.  I would like to add the descriptions as items to 
>> the combobox with the id as index.  (Something like: 
>> self.cmbSearch.insertItem(description, id)).  But I'm getting 'index 
>> out of range' errors.  Could this be because the indexes need to be 
>> in consecutive order (and the series of id's isn't) ?  I can't find 
>> info on this in the pyqt-documentation...
> I'm new myself, but I've done a few small apps since starting. The 
> TrollTech docs are very useful (http://doc.trolltech.com/), but I 
> didn't find an easy way to do what you're after (having a Combo Box 
> with a "value" for each entry, a la HTML forms).
> The way I got around it was to separately store a mapping (or what's 
> the python term? Dictionary or something?) of either the labels, or 
> the combo box index, to the values you're after. So, when you populate 
> the entries in the field, also populate a mapping. Then, to get the 
> value, you use the text or index to look up the mapping to get the value.
> The index value of the combo box is solely a numeric item number for 
> the items in the list (AFAIK).
Tnx for your response Trevor!  I was already thinking in the same 
direction...  Seems a good way to do this.


More information about the PyQt mailing list