[PyQt] How to link a dict and a QComboBox

David Boddie david at boddie.org.uk
Sat Sep 6 01:53:47 BST 2008


On Thu Sep 4 19:25:24 BST 2008, Sven Grunewaldt wrote:

> 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?

You can add values for each item in the combo box with its setItemData()
method:

http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qcombobox.html#setItemData

You would later call its itemData() method with the index obtained from
currentIndex(), or in a slot connected to its currentIndexChanged() signal:

http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qcombobox.html#currentIndexChanged

David


More information about the PyQt mailing list