Issue
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:
button()
returns the buttons that cause the event, which means that it will always be0
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.
Answered By - musicamante
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.