Skip to content

Commit

Permalink
不显示鼠标悬停颜色
Browse files Browse the repository at this point in the history
  • Loading branch information
892768447 committed Nov 8, 2019
1 parent 66582ba commit 066d15c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion QTreeWidget/ParentNodeForbid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,32 @@
@description: 父节点不可选中
"""
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QStyledItemDelegate,\
QStyle


__Author__ = 'Irony'
__Copyright__ = 'Copyright (c) 2019'
__Version__ = 1.0


class NoColorItemDelegate(QStyledItemDelegate):

def paint(self, painter, option, index):
if option.state & QStyle.State_HasFocus:
# 取消虚线框
option.state = option.state & ~ QStyle.State_HasFocus
if option.state & QStyle.State_MouseOver and index.data(Qt.UserRole + 1):
# 不显示鼠标悬停颜色
option.state = option.state & ~ QStyle.State_MouseOver
super(NoColorItemDelegate, self).paint(painter, option, index)


class Window(QTreeWidget):

def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.setItemDelegateForColumn(0, NoColorItemDelegate(self))

# 父节点(不可选中)
pitem1 = QTreeWidgetItem(self, ['parent item 1'])
Expand Down

0 comments on commit 066d15c

Please sign in to comment.