Results 1 to 3 of 3

Thread: Basic question on QComboBox

  1. #1
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Post Basic question on QComboBox

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

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Basic question on QComboBox

    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

  3. The following user says thank you to momesana for this useful post:

    Raccoon29 (9th May 2008)

  4. #3
    Join Date
    Apr 2008
    Location
    Pavlodar, Kazakhstan
    Posts
    22
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Basic question on QComboBox

    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().

  5. The following user says thank you to mitro for this useful post:

    Raccoon29 (9th May 2008)

Similar Threads

  1. Replies: 2
    Last Post: 21st February 2008, 22:35
  2. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  3. Replies: 5
    Last Post: 4th August 2006, 10:12
  4. Basic question on new and delete
    By jcr in forum General Programming
    Replies: 25
    Last Post: 14th February 2006, 15:09
  5. Using QSA: A very basic question
    By yogeshm02 in forum Newbie
    Replies: 3
    Last Post: 26th January 2006, 07:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.