Qt-interest Archive, May 2002
Colors in QListViewItem
Message 1 in thread
Hello,
How do I change the color of the text in a QListViewItem? Is there an easy
way, or do I have to reimplement QListView::paintCell() ?
Thanks,
Zach Hobbs
Message 2 in thread
On Friday 17 May 2002 01:08 pm, Zach Hobbs wrote:
> How do I change the color of the text in a QListViewItem? ...
we had it working by sub classing QListViewItem and reimplement its
paintCell() as in the follows,
void QxViewItem::paintCell(QPainter * p, const QColorGroup & cg, int column,
int width, int align)
{
QColor color;
switch (type) // type is a member of the item
{
case 'B':
color = QColor(0, 0, 255);
break;
case 'R':
color = QColor(255, 0, 0);
break;
default:
color = QColor(0, 0, 0);
}
QColorGroup _cg( cg );
QColor oldColor = _cg.text();
_cg.setColor(QColorGroup::Text, color);
QListViewItem::paintCell( p, _cg, column, width, align );
_cg.setColor(QColorGroup::Text, oldColor);
}