eric
eric

Reputation: 8088

Highlight item with mouse hover in QTreeView?

I have a QStandardItemModel that I am displaying as a QTreeView with multiple columns. How can I make it highlight rows when the mouse hovers over them?

Related pages

Upvotes: 5

Views: 6235

Answers (2)

eric
eric

Reputation: 8088

Lahiru's answer is easy to translate to PyQt/PySide, as the input to setStyleSheet doesn't need any modification: it is the same in Qt/PyQt/PySide:

treeView.setStyleSheet("QTreeView::item:hover{background-color:#999966;}")

I found it helpful to read the Overview of style sheet syntax for Qt. Also, this answer has some nice examples on using style sheets in PySide/PyQt.

Upvotes: 1

Lahiru Chandima
Lahiru Chandima

Reputation: 24128

You can achieve this by a stylesheet

treeView->setStyleSheet("QTreeView::item:hover{background-color:#FFFF00;}");

Upvotes: 6

Related Questions