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())
You're confusing with the
type()property of all QEvents.In fact, in the
Typeenum of QEvent,MouseMovehas value 5.If you want to check the pressed buttons of a mouse move event, use the
buttons()property of QMouseEvent.Note that
button()andbuttons()are not the same thing:button()returns the buttons that cause the event, which means that it will always be0for 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 havemouseTrackingenabled. This happens by default in some special cases (usually for scroll area based classes), for instance in a QGraphicsView with interactive items.