PDA

View Full Version : Text color of QTreeWidgetItem when item is selected - Qt 4.8.6



dictoon
21st February 2015, 15:47
Hi,

I'm setting the text color of a particular QTreeWidgetItem using setForeground(). This works as long as the item is not selected. When the item is selected, the text color I've set is not respected.

I've found another thread with the same question (http://www.qtcentre.org/threads/24714-QTreeWidgetItem-text-color), unfortunately I don't understand how the OP fixed his issue.

Help gladly appreciated!

Franz

Santosh Reddy
23rd February 2015, 05:59
In the referred post OP is re-implementing the paintEvent() function.

If your case if it is just to change the foreground color, you could do it using below code, make sure to remove other palette changes you might have done.


item->setForeground(column, QBrush(QColor(Qt::red)));

dictoon
23rd February 2015, 13:23
Thanks for your answer.


If your case if it is just to change the foreground color, you could do it using below code, make sure to remove other palette changes you might have done.

As I said in my question, that's exactly what I'm doing, and it works as long as the item is not selected. I'm looking for a way to change the color of the item when it's selected.

Franz

Santosh Reddy
23rd February 2015, 14:18
ok then you could use this


treeWidget.setStyleSheet("QTreeWidget:item:selected:active { color: red }");

dictoon
23rd February 2015, 17:34
I thought about using stylesheets... But there is often a large number of items in that tree widget; can I "polish" items individually?

dictoon
28th February 2015, 08:46
Santosh, what you propose is changing the text color of all selected items. As stated in my original question, this isn't what I'm after. I'm trying to change the text color of one or a few items. I succeed in doing so by using setForeground(), but this color isn't used when the item is selected.

Any idea?