MouseArea drag group, and drag signals
-
How do I attach handlers like
onDragStarted
when I'm using the drag group of properties in aMouseArea
object? Within theMouseArea
,onDragStarted
is undefined, anddrag.onDragStarted
is undefined. If I refer toDrag.onDragStarted
, it's not undefined, but it's never called. -
drag in mouse area is group property. It is not of type Drag. If you would like to catch drag signal, attach Drag property to an Items to be dragged. Inside the Item to be dragged use the onDragStarted.
-
drag in mouse area is group property. It is not of type Drag. If you would like to catch drag signal, attach Drag property to an Items to be dragged. Inside the Item to be dragged use the onDragStarted.
@dheerendra
Okay, I've added a Drag property to the Rectangle I'm trying to drag, as described in http://doc.qt.io/qt-5/qml-qtquick-drag.html#details, and added a Drag.onDragStarted handler to the Rectangle. It's not being invoked.So I decided to experiment with Drag.dragType. If I set it to Drag.None or Drag.Internal, the dragging works, but I don't get the signal. But if I set it to Drag.Automatic, then I get the signal, but dragging doesn't work. Instead, the mouse pointer turns into a ForbiddenCursor, and the Rectangle just jumps to the new location when the mouse button is released.
Any more ideas?
-
Just to make it work, you can check for onXChanged of corresponding items to be dragged.
-
I solved this issue by adding explicit
dragActive
property to theMouseArea
. Sample code:MouseArea { id: mouseArea drag { target: myItem axis: Drag.YAxis } property bool dragActive: drag.active onDragActiveChanged: { if(drag.active) { // ... // Dragging started } else { ... // Dragging finished } } }