Qt,如何更改QComboBox的一个项目的文本颜色? (C ++) [英] Qt, How do I change the text color of one item of a QComboBox? (C++)
问题描述
我无法弄清楚如何更改QComboBox的一个特定项目的文本颜色。我可以更改项目的背景颜色:
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根本没有效果,Qt 4.6,Ubuntu 10.04)
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.
感谢您的帮助!
推荐答案
几乎像你建议的,但你必须将角色更改为Qt :: TextColorRole。
Almost like you propose but you have to change the role to "Qt::TextColorRole".
comboBox-> setItemData(0,Qt :: red,Qt :: TextColorRole);
comboBox->setItemData(0, Qt::red, Qt::TextColorRole);
这篇关于Qt,如何更改QComboBox的一个项目的文本颜色? (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!