You can create custom QListWidgetItem and use a "index-based" color.
{
private:
static const int numberOfColors = 3;
static QColor ColouredItem
::colorList[numberOfColors
];
public:
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)};
class ColouredItem : QListWidgetItem
{
private:
static const int numberOfColors = 3;
static QColor ColouredItem::colorList[numberOfColors];
public:
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)};
To copy to clipboard, switch view to plain text mode
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.
Bookmarks