Results 1 to 6 of 6

Thread: QcomboBox items

  1. #1
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question QcomboBox items

    hey there i have a QComboBox with 3 different items inside it. i basically want to select 1 of the items and then i want them to alter an integer, i. e. if selection 1 is chosen from the QComboBox then int selection = 1, if item 2 is chosen then int selection = 2 etc. i was looking at the QComboBox library but i cant find how to do this - any idea's?

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QcomboBox items

    Qt Code:
    1. int a = cmb->currentIndex () + 1;
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

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

    tpf80 (16th May 2007)

  4. #3
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QcomboBox items

    hey there where do i stick that code? do i put it in a seperate function as a slot or in the constructor of the QComboBox?

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QcomboBox items

    ... Where would you use that int selection? Put the example piece of code there and replace cmb with the pointer to your combo box.

  6. #5
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QcomboBox items

    hey there i tried the currentIndex() function but it only works for the first item in the QComboBox and then gives the same output for the rest of the items as well. is there a way to distinguish between the itesm in the QCombobox so that they each give a different value for int selection, or call a seperate function each?

  7. #6
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QcomboBox items

    Use next signal
    Qt Code:
    1. void QComboBox::highlighted ( int index ) [signal]
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

Similar Threads

  1. Replies: 1
    Last Post: 15th January 2009, 11:34
  2. QComboBox not showing all items
    By musikit in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2008, 17:01
  3. Occurance of Duplicate items in QComboBox
    By merry in forum Qt Programming
    Replies: 8
    Last Post: 12th September 2007, 16:05
  4. Automatically add items to a QComboBox (Qt4)
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2006, 16:32
  5. [QT3] QComboBox: Disable adding items on Enter-keypress
    By BrainB0ne in forum Qt Programming
    Replies: 7
    Last Post: 14th January 2006, 20:43

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.