PDA

View Full Version : Need help setting the QTreeView selectedItem color



loren_rogers
21st November 2011, 17:44
Hey gang,
I'm using Qt 4.8.0 and I have a QTreeview object where I am trying to set the selected color. I've been reading docs and I assume this is the Hightlighted color. Stylesheets are not working and the following code is also not working:
QPalette p = ui._librariesView->palette();
p.setColor(QPalette::HighlightedText, Qt::red);
p.setColor(QPalette::Highlight, Qt::red);
ui._librariesView->setPalette(p);
please help.
Thanks
/Loren

cincirin
23rd November 2011, 11:15
Maybe you should use item delegate (http://doc.qt.nokia.com/latest/qitemdelegate.html) for displaying selected items as you want.
Reimplement QItemDelegate:: paint (http://doc.qt.nokia.com/latest/qitemdelegate.html#paint) and follow the example from docs.