Results 1 to 4 of 4

Thread: Change the value of a combobox

  1. #1
    Join Date
    Oct 2010
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Change the value of a combobox

    Hi all, I have a combobox with two items, male and female.

    I query a database, if the current record has gender male, i want set the combobox item to "male". If the current record is gender female I want to set the combobox item to "female".

    How do I achieve this? I'm sure it's pretty simple, I just can't seem to get it to work.

    Oh and a quick other question. I have another combobox which uses a model. This comobobox automatically shows the first record by default. How do i change it so that the combox is blank to begin with?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Change the value of a combobox

    I'm sure it's pretty simple, I just can't seem to get it to work.
    Show what you have tried so far.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Change the value of a combobox

    hi,
    I query a database, if the current record has gender male, i want set the combobox item to "male". If the current record is gender female I want to set the combobox item to "female".
    To find the text in the combo, use findText(); this will return the index of the searched string;
    Then set the currentindex using setCurrentIndex() with the searched index.
    Qt Code:
    1. myCombo->setCurrentIndex(myCombo->findText(rs.value(0).toString()))
    To copy to clipboard, switch view to plain text mode 

    This comobobox automatically shows the first record by default. How do i change it so that the combox is blank to begin with
    simply put -1 in setCurrentIndex();
    Qt Code:
    1. myCombo->setCurrentIndex(-1);
    To copy to clipboard, switch view to plain text mode 

    How do I achieve this? I'm sure it's pretty simple, I just can't seem to get it to work.
    Just gothrough all the Qtexamples in your free time. we cant get quality results without knowing much about it

    hope it helps
    Bala
    Last edited by BalaQT; 23rd February 2011 at 13:01.

  4. The following user says thank you to BalaQT for this useful post:

    zeFree (12th September 2012)

  5. #4
    Join Date
    Oct 2010
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change the value of a combobox

    Wow thank you bala. This works a treat.

    Thanks for your time and trouble

Similar Threads

  1. Color ComboBox
    By ioannis in forum Qt Programming
    Replies: 14
    Last Post: 23rd March 2016, 07:08
  2. DockWidgetArea change and layout direction change
    By mstegehu in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2012, 21:24
  3. Help ComboBox
    By vinny gracindo in forum Newbie
    Replies: 3
    Last Post: 20th November 2009, 19:41
  4. ComboBox of bmp:s
    By SailinShoes in forum Qt Programming
    Replies: 2
    Last Post: 5th March 2008, 15:22
  5. Replies: 8
    Last Post: 15th May 2007, 09:21

Tags for this Thread

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.