Text color of QTreeWidgetItem when item is selected - Qt 4.8.6
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, unfortunately I don't understand how the OP fixed his issue.
Help gladly appreciated!
Franz
Re: Text color of QTreeWidgetItem when item is selected - Qt 4.8.6
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.
Re: Text color of QTreeWidgetItem when item is selected - Qt 4.8.6
Thanks for your answer.
Quote:
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
Re: Text color of QTreeWidgetItem when item is selected - Qt 4.8.6
ok then you could use this
Code:
treeWidget.setStyleSheet("QTreeWidget:item:selected:active { color: red }");
Re: Text color of QTreeWidgetItem when item is selected - Qt 4.8.6
I thought about using stylesheets... But there is often a large number of items in that tree widget; can I "polish" items individually?
Re: Text color of QTreeWidgetItem when item is selected - Qt 4.8.6
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?