View Full Version : font color of list view

5th May 2011, 09:47
hello every on i want to ask that i have a list view in which values are loaded from the file i want to ask that can i change font color of the list view as i have search the option but it does not give option to change font color plz help me


6th May 2011, 08:52
Are you using QListView with a model, or a QListWidget?
In both cases you have to set the font in the item, not the list.
See QListWidgetItem.

7th May 2011, 08:51
sir i didnt get u how to change font color in item can u kindly quid me little more .

7th May 2011, 09:49
You can change font color form Style Sheet .

Righ click on the list view and chose change style sheet >add color>color

7th May 2011, 09:55
actually for i want different color for different item in the list like i want some row to be red and some to be green based on some values. how can i do that

7th May 2011, 12:33
i tried to do it by using HTML Markup but it didn't work .. it seems like it only work with text Widgets.

i don't think it is possible to change a single item color in list view.

8th May 2011, 15:49
ok sir thanks but can any one tell me how to use that QBrush and foreground option of qlistwidgetitem my it will help solving problem

8th May 2011, 16:07
You can create custom QListWidgetItem and use a "index-based" color.

class ColouredItem : QListWidgetItem
static const int numberOfColors = 3;
static QColor ColouredItem::colorList[numberOfColors];

void updateItemColor()
int row = this->listWidget()->row(this);
this->setForeground(QBrush(colorList[row % numberOfColors]));

QColor ColouredItem::colorList[numberOfColors] = {QColor::fromRGB(255, 0, 0), QColor::fromRGB(0, 255, 0), QColor::fromRGB(0, 0, 255)};

When you need to update the color just call that updateItemColor function.

If you need a "type-based color". Just change the colorList[row % 3] to get color based on type or something else.