Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 513
Jimmie Avatar asked Feb 05 '10 21:02

Jimmie


2 Answers

QListWidget t;
t.addItem("first");
t.addItem("second");
t.item(0)->setForeground(Qt::red);
t.item(1)->setForeground(Qt::blue);
like image 136
PiedPiper Avatar answered Nov 16 '22 12:11

PiedPiper


This can also be done by stylesheets. E.g.:

QListWidget::item {
    color:#00ff00;
    background-color:transparent;
}

Set it by setStylesheet(...)

like image 2
ManuelSchneid3r Avatar answered Nov 16 '22 13:11

ManuelSchneid3r