Take the 2-minute tour ×

I can't seem to get any mouse clicks in a QTreeWidget. I have tried...

  • ...overriding mousePressEvent, but it never runs at all. Not even to log a message.
  • ...using an event filer. It works for everything but mouse clicks.
  • ...using delegates. Their editor events work fine, but only when over an item, which isn't enough
  • ...making sure everything is being added to layouts. I used QTCreator and the output is using layout.addWidget(). I am also adding the widget instance to a layout in the main window.

I was able to use the answer to register the widget as an event filter for the QTreeWidget like so:

# In __init___
    # self.tree is the QTreeWidget

def eventFilter(self, target, event):
    This widget is an event filter for the tree, so this function is triggered 
    # 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
share|improve this question
Can you show some code? –  Junuxx Jun 26 '12 at 0:15
add comment

1 Answer

up vote 3 down vote accepted

because what you can see (and click) on QTreeWidget is actually it's viewport(). You sholud install event filter on it's viewport() instead.

share|improve this answer
add comment

Your Answer


