PDA

View Full Version : Need help on setting up Defult text on QCombo box



Askar
23rd February 2011, 07:16
Dear friends,
I need Help on how to set default text to be displayed on combo box before selecting an item from it, i used the following code,

QComboBox cmb;
cmb.addinsertItem(-1,"Select text");
cmb.additem("abcdef");
cmb->setCurrentIndex(-1);

but the "Select Text" is not displayed on the combo box by defualt, instead it is displayed as one of the item in the combo box drop down list.....

can any one help me to solve this,
Thanks in advance,

nikhilqt
23rd February 2011, 07:27
-1 is the value when no item is set. Make the current Index to '0'. And also make the 'Select Text' item index as '0' too.

Askar
23rd February 2011, 08:09
s thanks for your response nikhilqt

i dont want to add it as an item in the combo box. is it possible to set "Select Text" as default till i select an item from combo?

nikhilqt
23rd February 2011, 11:50
That's what i am saying. It's your logic to do that. Check out the signals of QComboBox like currentIndexChanged(...), activated(...). On slots put your logic such that the 'Select Text' would be default option if no item is selected. Once selected remove that item from the combobox list.