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?
Re: Change the value of a combobox
Quote:
I'm sure it's pretty simple, I just can't seem to get it to work.
Show what you have tried so far.
Re: Change the value of a combobox
hi,
Quote:
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.
Code:
myCombo->setCurrentIndex(myCombo->findText(rs.value(0).toString()))
Quote:
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();
Code:
myCombo->setCurrentIndex(-1);
Quote:
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
Re: Change the value of a combobox
Wow thank you bala. This works a treat. :D
Thanks for your time and trouble :)