QMouseEvent is of type 5? What is type 5?

65 views Asked by At

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())
1

There are 1 answers

1
musicamante On BEST ANSWER

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:

  • button() returns the buttons that cause the event, which means that it will always be 0 for mouse move events, since the event is originated by the movement, not a button pressure;
  • buttons() returns the buttons when the event was generated (and you're probably interested in this one);

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.