Mouse events for rectangles within a flickable
-
wrote on 14 Feb 2011, 15:52 last edited by
Hi
In my QML app, I have a Flickable containing several Rectangles, each of which has a MouseArea filling the whole Rectangle. These Rectangles are serving as buttons, so they move into a "pressed" state on the onPressed event of the MouseArea, and back to "unpressed" on the onReleased event.
The problem is that if the user presses a button, doesn't release it, and starts flicking, the onReleased event is never fired and my button remains in the "pressed" state.
I guess this is intended behaviour, because we don't want the button doing its "click" action when only a flick has occurred.
What's the best way of working round this?
-
wrote on 14 Feb 2011, 16:24 last edited by
Hmmm... a workaround may be to reset the state if the parent flickable goes into a flick, for instance by connecting to the onFlickStarted signal.
-
wrote on 14 Feb 2011, 16:27 last edited by
Yes I feared that might be the case, refactoring to provide all my buttons with access to a Flickable will be a pain.
-
wrote on 14 Feb 2011, 16:38 last edited by
I did not claim it is the only way to do it. Just a possibility that occurred to me, though it is not very elegant.
-
wrote on 15 Feb 2011, 01:01 last edited by
Hi,
There is an "onCanceled handler":http://doc.qt.nokia.com/4.7-snapshot/qml-mousearea.html#onCanceled-signal that was added for this very reason :-) You could also consider binding the state's when clause to mouseArea.pressed -- it will turn to false when flicked.
Regards,
Michael -
wrote on 20 Jun 2014, 01:02 last edited by
Thanks, really helped.