Highlight item with mouse hover in QTreeView?
Asked Answered
C

2

5

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

Cyndicyndia answered 2/3, 2015 at 4:34 Comment(2)
Doesn't QTreeView highlight items by default on mouse hover?Erotomania
@LahiruChandima No.Cyndicyndia
E
6

You can achieve this by a stylesheet

treeView->setStyleSheet("QTreeView::item:hover{background-color:#FFFF00;}");
Erotomania answered 2/3, 2015 at 6:56 Comment(0)
C
1

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.

Cyndicyndia answered 2/3, 2015 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.