Qt QML 6.2.1. How to identify the direction of the dragging event in MouseArea?
-
I'm using MouseArea and I'd like to identify whether user drags the mouse to the right or to the left. There's a signal
positionChanged(MouseEvent mouse)
, but it neither provides information about the direction nor about the previous and current coordinates. Do you have any advices? Thank you in advance. -
UPD.
I found a solutions by myself. The only thing you need to do is to introduce a variable which stores a previous position of the cursor. Then you compare it with the current mouse X position each time mouse is moved (onPositionChanged()
). If mouse X position is bigger, then this is a right move gesture. If mouse X position is smaller, then this is a left move gesture.
Note: exclude 0 as it leads to undesired behaviour.
Don't forget to update the variable storing the last cursor's position. From my experiece the difference would always be 1, 0 or -1 (we handled 0 case), because the signal is emitted each time the mouse moves (even on a signle pixel).