我似乎无法在QTreeWidget中点击任何鼠标。我试过......
我能够使用答案将小部件注册为QTreeWidget的事件过滤器,如下所示:
# In __init___
# self.tree is the QTreeWidget
self.tree.viewport().installEventFilter(self)
def eventFilter(self, target, event):
"""
This widget is an event filter for the tree, so this function is triggered
automatically
"""
# Print on right-click
if (event.type() == QEvent.MouseButtonPress and
event.button() == Qt.RightButton):
print("Right Click")
# Don't block/accept the event
return False
答案 0 :(得分:4)
因为您在QTreeWidget
上看到(并点击)的内容实际上是viewport()
。你的安装事件过滤器是viewport()
而不是。{/ p>