Mouse events for rectangles within a flickable
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?
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.
Yes I feared that might be the case, refactoring to provide all my buttons with access to a Flickable will be a pain.
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.
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.
Thanks, really helped.