pythonpyqtqmouseevent

QMouseEvent is of type 5? What is type 5?


I have a Widget that has mouseTracking set to True and the following code prints 5, even though I'm not pressing any buttons. Additionally type 5 isn't mentioned in the MouseButton enum docs. So what is type 5 and why is the mouseEvent of type 5?

The code:

def mouseMoveEvent(self, event: QMouseEvent) -> None:
    print(event.type())

Solution

  • You're confusing with the type() property of all QEvents.

    In fact, in the Type enum of QEvent, MouseMove has value 5.

    If you want to check the pressed buttons of a mouse move event, use the buttons() property of QMouseEvent.

    Note that button() and buttons() are not the same thing:

    Finally, mouseMoveEvent() is always called for widgets that have mouseTracking enabled. This happens by default in some special cases (usually for scroll area based classes), for instance in a QGraphicsView with interactive items.