PDA

View Full Version : Change the value of a combobox



Splatify
23rd February 2011, 11:50
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?

high_flyer
23rd February 2011, 12:05
I'm sure it's pretty simple, I just can't seem to get it to work.
Show what you have tried so far.

BalaQT
23rd February 2011, 12:51
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.

myCombo->setCurrentIndex(myCombo->findText(rs.value(0).toString()))


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

myCombo->setCurrentIndex(-1);


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

Splatify
23rd February 2011, 13:38
Wow thank you bala. This works a treat. :D

Thanks for your time and trouble :)