PDA

View Full Version : Basic question on QComboBox



Raccoon29
9th May 2008, 16:39
Hi,
is it possible to store a code as text and a number as an hidden ID related to each code in a QComboBox?

Something like for select/option for HTML that let's declare a value for each option, and an arbitrary text to show it. (I ask this because I would like to avoid the use of a parallel QVector that contains the IDs)

Thanks in advance

momesana
9th May 2008, 17:28
if you take a closer look at QComboBox::addItem you will find out that some of the overloads take an additional QVariant argument. Use that to set the id or whateva data you want to associate with it. You can also use setItemData and itemData to set and retrieve the data respectively.

cheers

mitro
9th May 2008, 17:41
If you want to add additional data to an item after it's been created you may use QComboBox::setItemData() function. To obtain stored value use QComboBox::itemData().