【问题标题】:Highlight item with mouse hover in QTreeView?在 QTreeView 中用鼠标悬停突出显示项目?
【发布时间】:2015-05-02 09:21:39
【问题描述】:

我有一个QStandardItemModel,我将其显示为具有多列的QTreeView。当鼠标悬停在行上时,如何使其突出显示行?

相关页面

【问题讨论】:

  • 鼠标悬停时 QTreeView 默认不突出显示项目吗?
  • @LahiruChandima No.

标签: qt pyqt pyqt4 pyside


【解决方案1】:

您可以通过样式表来实现这一点

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

【讨论】:

    【解决方案2】:

    Lahiru's answer 很容易翻译成 PyQt/PySide,因为 setStyleSheet 的输入不需要任何修改:在 Qt/PyQt/PySide 中也是一样的:

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

    我发现阅读Overview of style sheet syntax for Qt 很有帮助。另外,this answer 有一些在 PySide/PyQt 中使用样式表的好例子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      相关资源
      最近更新 更多