How to get new parent, when DragHandler is used ?
-
Hello, How to get(detect) new parent for draggable item, when DragHandler is used after dropping ?
I can get new parent for MouseArea when i use MouseArea as Drag Manager(which contains draggable Item) (accrording to examples) , but i can't use '"draggable item(dragrect) within MouseArea" way because TapHandler within draggable Item (dragrect) blocks events to "Drag Manager" MouseAreaP.S. I can change special property (parentItem) from droping event handler (DropOut::onEntered) of draggable object, but i want do it int draggable event handler because user may cancel dragging, so i need to detect new parent in draggable object when it enter in potentioal parent area
import QtQuick import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQuick.Shapes 1.9 import QtQuick.Layouts 1.0 Window { id: window width: 640 height: 480 visible: true title: qsTr("Hello World") Rectangle { id: mainrect anchors.fill: parent ColumnLayout { anchors.fill: parent Rectangle { Layout.fillWidth: true Layout.minimumHeight: 200 color: "green" DropArea { id: srcrect anchors.fill: parent Item { id: marea anchors.fill: parent Rectangle { id: dragrect anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter color: "red" width: 60 height: 80 z: 20 DragHandler { id: dhandler } property Item parentItem: marea states: State { when: dhandler.active PropertyChanges { target: dragrect parent: parentItem } AnchorChanges { target: dragrect anchors { verticalCenter: undefined horizontalCenter: undefined } } } Drag.active: dhandler.active Drag.hotSpot.x: width/2 Drag.hotSpot.y: height/2 property bool dactive: dhandler.active onDactiveChanged: { if (!dactive) { console.log("!dactive") parent = Drag.target !== null ? Drag.target : parentItem if (Drag.target !== null) { parentItem = Drag.target console.log("new parentItem") } } if (dactive) { console.log("dactive") parent = Drag.target !== null ? Drag.target : parentItem if (Drag.target !== null) { parentItem = Drag.target console.log("new parentItem") } } } MouseArea { anchors.fill: parent enabled: false drag.target: dragrect propagateComposedEvents: true onReleased:(mouse)=> { console.log("test") mouse.accepted = false } onPressed: (mouse)=> { console.log("test") mouse.accepted = false } } TapHandler { enabled: true //anchors.fill: parent onTapped: function(mouse) { console.log("tap") mouse.accepted = false } } } } } } Rectangle { Layout.fillWidth: true Layout.minimumHeight: 200 color: gggg.containsDrag ? "grey" : "blue" //opacity: 0.7 DropArea { id: gggg anchors.fill: parent onDropped: { console.log("dropped") } } } } } } -
Since items can only be dropped on a drop area, just connect to all drop areas'
droppedsignal. The signal is emitted with a drag event argument, from which you can establish the source, e.g. the dragged object.Have in mind though, that a drop doesn't cause reparenting automatically. So technically, there is no new parent, unless the app sets it explicitly.