Highlight item with mouse hover in QTreeView?

落花浮王杯 提交于 2019-12-07 07:56:57

问题


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

  • How to catch mouse over event of QTableWidget item in pyqt?: similar question using QTableWidget instead of Q*View.
  • Customizing QListView: suggests it is possible to do it very easily with stylesheets, but I don't quite follow the c++.
  • How to highlight the entire row on mouse hover in QTableWidget
  • QListView selection with highlight/hover

回答1:


You can achieve this by a stylesheet

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



回答2:


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.



来源:https://stackoverflow.com/questions/28802763/highlight-item-with-mouse-hover-in-qtreeview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!