[Interest] QtQuick Mouse operation to connect two objects
Shawn.Rutledge at digia.com
Thu May 8 10:13:24 CEST 2014
On 8 May 2014, at 9:06 AM, Andreas Cord-Landwehr wrote:
> Hi, I am looking for a proper way on how to apply a mouse press-release operation on two QtQuick objects. For simplicity, say I have two rectangles on the QtQuick scene. Now I want to press the mouse at one of them and release it at the other rectangle. By this, I want to listen to the onPressed signal of the first and to the onReleased signal of the second rectangle. (the idea behind: I create a connection between both objects)
> My current approach was to use MouseArea items filling each rectangle. Yet, when pressing the mouse at the first rectangle and releasing at at the other, I only get pressed(MouseEvent) and released(MouseEvent) signals from the first rectangle, i.e. the rectangle where I started the press.
> What would be a correct way to do this?
That doesn't work because QQuickWindow keeps track of the mouse grabber: the item which accepted the press will be the one which gets all subsequent mouse events up to and including the release. There is the concept of stealing mouse events from a child item, e.g. Flickable can still flick even if you happened to start with your finger pressing a MouseArea inside the Flickable; if you drag far enough then Flickable will "steal" the grabber status for itself. But MouseArea doesn't do that. So you will probably need to use one MouseArea, implement onPositionChanged (which will be called only when the mouse button is pressed, unless you enable hover) and pay attention to the position (mouse.x and/or mouse.y) to see whether you crossed over the boundary where you would have wanted two MouseAreas side-by-side.
More information about the Interest