How to change the text color of items in a QListWidget?

Jimmie picture Jimmie · Feb 5, 2010 · Viewed 22.4k times · Source

I want to change the text color of the items in QListWidget.
For example, some items are in red text while others are in blue text. How do I do that? Thank you.

Answer

PiedPiper picture PiedPiper · Feb 6, 2010
QListWidget t;
t.addItem("first");
t.addItem("second");
t.item(0)->setForeground(Qt::red);
t.item(1)->setForeground(Qt::blue);