1
votes

at the moment I have to code some mouse-events in C++. I know that there are mouse events for press, release, move, double click.

What I wonder about is how to distinguish between events when they are used in a different order. Lets say I do:

Mouse move -> Mouse click -> Mouse move -> Mouse release

How can I distinguish between the first an the second Mouse-move event?

I solved that by using a flag "Mouse-click-flag" that is set true while running the Mouse-click-event. In the mouse-move routine, I have an if-Statement checking (Mouse-click-flag== true), that decides weather or not to run the Mouse-click-event-routine. This works but it seemes very complicated.

How would one solve this?

Thank you

itelly

1
If mouse tracking is switched off, then you get move events only when the mouse is down. Unless you need to know when the mouse is moving even when the mouse button is not down? You can also get the pressed mouse buttons from the QMouseEvent object.thuga

1 Answers

1
votes

What you're doing is correct. You would also want to set Mouse-click-flag to false on your mouse release event, but you've probably figured that out and just didn't say it. You mention running a mouse-click-event routine on the first move. Is there a reason you don't run that in the mousePressEvent routine? There are good reasons sometimes...just confirming that's what you need.

If you only care about mouse move events while the user has the mouse down, then as thuga said, turn off mouse tracking by calling "setMouseTracking" on the widget and set it to false. Then you will only ever get click-move-release patterns.