Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt, How do I change the text color of one item of a QComboBox? (C++)

I cannot figure out how to change the text color of one particular item of a QComboBox. I was able to change the Background color of an item:

comboBox->setItemData(i, Qt::green, Qt::BackgroundRole);

(Qt::ForegroundRole had no effect at all, Qt 4.6, Ubuntu 10.04)

and I was able to change the text color of all items with a stylesheet but I cannot figure out how to change the text color of one specified item.

Thanks for your Help!

like image 248
Linoliumz Avatar asked Jun 18 '10 14:06

Linoliumz


1 Answers

It's almost like you propose, but you have to change the role to Qt::TextColorRole.

comboBox->setItemData(0, QBrush(Qt::red), Qt::TextColorRole);  
like image 152
Lefteris Banos Avatar answered Sep 16 '22 16:09

Lefteris Banos