View Full Version : QListWidget/QTreeWidget, etc selected item color
Arthur
12th May 2006, 10:47
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?
wysota
12th May 2006, 12:35
Yes. Use setData() with Qt::TextColorRole.
I think he means the selection color. QItemDelegate uses QPalette::Highlight for drawing the item selection.
QPalette p = treeWidget->palette();
p.setColor(QPalette::Highlight, Qt::red);
// 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);
Arthur
15th May 2006, 16:48
Thanks, it works.
However it does not work when the item is editable :(
Do you know a solution for that as well?
wysota
15th May 2006, 16:50
You probably need to use QPalette::Active colourgroup.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.