PDA

View Full Version : QTreeWidgetItem text color



Arthur
13th October 2009, 15:51
Hello,

Using Qt 4.4.1, Windows

I have a QTreeWidget, with items that can have other colors than standard.

When an item is NOT selected, it works perfectly. When an item is selected, it does not. If the tree does not have the focus, the selected item also does not have the color I want.

This is a sample of the Paint function in my tree item delegate: None of the palette settings (In this sample QPalette:All, but any other setting also gives the result) work.

It doesn't matter if I give the tree item a different color or change text and foreground color of the treeItem: when an item is the current item, it is White (when highlighted) or Black when the tree does not have the focus...



QColor dirtyColor = Qt::red
QPalette p = pTree->palette();
QPalette old_palette = p;
p.setColor(QPalette::All, QPalette::Text, dirtyColor);
p.setColor(QPalette::All, QPalette::HighlightedText, dirtyColor);
p.setColor(QPalette::All, QPalette::BrightText, dirtyColor);

pTree->setPalette(p);

pItem->setTextColor(index.column(), dirtyColor);
pItem->setForeground(index.column(), dirtyColor);

QItemDelegate::paint(painter, option, index);
pTree->setPalette(old_palette);


Does anyone know what to do?

Arthur
13th October 2009, 16:45
Changing QStyleOptionViewItem worked...

faldzip
13th October 2009, 17:59
Didn't QTreeWidgetItem::setForeground() suit your needs?