PDA

View Full Version : Problem with QComboBox



wagmare
29th November 2011, 06:58
Hi friends,
i tried to change the text color of the QComboBox using QPalette ...


comboBox->setAutoFillBackground(true);


ComboBod::SelectedIndex(int index)
{
QPalette comboPalette = palette();
if(index == 1)
{
comboPalette.setColor(QPalette::Text, Qt::green);
comboPalette.setColor(QPalette::WindowText, Qt::green);
}else
{
comboPalette.setColor = parentWidget()->palette();
}

comboBox->setPalette(comboPalette);
}

but its not reflecting any change in the color ... i tried stylesheets also but not able to change the text of the comboBox .. only selection window text is changing ...

please hlp me ..

Thanks in advance

myta212
29th November 2011, 15:56
Hi wagmare,
Are you want to change all text color in QComboBox or only selected item?
I use this command :

comboBox->setStyleSheet(QString::fromUtf8("color: rgb(99, 146, 255);"));
this command will change all text color in QComboBox.

Best regards,

Toto

wagmare
30th November 2011, 05:24
thanks myta ...

i just want to change the text of the ComboBox and not the selection item ... last one u suggested i tried but it changing the selection items ...


Thanks once again

myta212
30th November 2011, 08:00
Hi wagmare,
You can use "selection-color" stylesheet method like this:

ui->comboBox->setStyleSheet("QComboBox { selection-color: black; color : blue; }");
This method will change all item at QComboBox, but you can change itemselected color like not selected.
Example :
default combobox item color = black
selected comboxbox item color = black
not selected comboxbox item color = blue

I think this method can solve your problem. Or we have missunderstanding about your problem ?
Thank you for your attention.

Best regards,

Toto

wagmare
1st December 2011, 10:25
Once again thanks for replying myta ..
ui->comboBox->setStyleSheet("QComboBox { selection-color: black; color : blue; }");

this you try with QComboBox .. it will change the color of the text when u press the QComboBox and shows the DropDown list ..
i required the text color change in QComboBox after selection had been done ...

i tried ur code .. as it is changing only the color of the dropdown selection of the comboBox and not the normal text in the comboBox after selecting ...
EX:after i selects one item in comboBox .. the item name will be displayed in comboBox .. that name should be shown in red color (for a particular item say index =1)...

Thanks again .....