Is there an easy way to change the color of a selected item in QListWidget and QTreeWidget, or do I have to do this by overriding the paint method in an ItemDelegate?
Is there an easy way to change the color of a selected item in QListWidget and QTreeWidget, or do I have to do this by overriding the paint method in an ItemDelegate?
Yes. Use setData() with Qt::TextColorRole.
I think he means the selection color. QItemDelegate uses QPalette::Highlight for drawing the item selection.
Qt Code:
// or even different colors for different color groups (states) // p.setColor(QPalette::Normal, QPalette::Highlight, Qt::green); // p.setColor(QPalette::Disabled, QPalette::Highlight, Qt::blue); treeWidget->setPalette(p);To copy to clipboard, switch view to plain text mode
J-P Nurmi
Arthur (15th May 2006)
Thanks, it works.
However it does not work when the item is editable![]()
Do you know a solution for that as well?
You probably need to use QPalette::Active colourgroup.
Bookmarks