[PyQt] How to link a dict and a QComboBox

Sven Grunewaldt strayer at olle-orks.org
Thu Sep 4 19:25:24 BST 2008


I'm facing a problem with data from a SQL database and my GUI.

Let's assume I have the following key => value dict:
sqlresult = {1: 20080909, 4: 202020, 5: 'bla', 6: 'blubb'}

How do I link it to a QComboBox?

In HTML this would be the standard <select> procedure:
<select>
	<option value="1">20080909</option>
	<option value="4">202020</option>
</select>

As far as I know there is no such thing like "value" for a QComboBox.
My guess would be to create a dict that links the two objects. Then I
could basically do something like this:
selectedValue = sqlresult[CBIndexToKey[QComboBox.selectedIndex()]]

But I feel a little bit uneasy about this... isn't there a better way?

Regards,
Sven Grunewaldt

...by the way...
How do I respond to something in this mailing list? When I just click
Reply I send a mail directly to the user who sent the original message.
(Sorry Phil!)
Do I just click "Reply" and change the receiver to
pyqt at riverbankcomputing.com? I don't understand how programs like
Thunderbird create the (very useful) thread-like view and don't want to
break this feature ;)


More information about the PyQt mailing list