<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to get new parent, when DragHandler is used ?]]></title><description><![CDATA[<p dir="auto">Hello, How to get(detect) new parent for draggable item, when DragHandler is used after dropping ?<br />
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" MouseArea</p>
<p dir="auto">P.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</p>
<pre><code>
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)=&gt; {
                                console.log("test")
                                mouse.accepted = false
                            }
                            onPressed: (mouse)=&gt; {
                                   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")
                }
            }
        }
    }
    }
}

</code></pre>
]]></description><link>https://forum.qt.io/topic/163003/how-to-get-new-parent-when-draghandler-is-used</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Apr 2026 11:52:53 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/163003.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 15 Aug 2025 16:27:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to get new parent, when DragHandler is used ? on Sat, 16 Aug 2025 19:50:12 GMT]]></title><description><![CDATA[<p dir="auto">Since items can only be dropped on a drop area, just connect to all drop areas' <code>dropped</code> <a href="https://doc.qt.io/qt-6/qml-qtquick-droparea.html#dropped-signal" target="_blank" rel="noopener noreferrer nofollow ugc">signal</a>. The signal is emitted with a <a href="https://doc.qt.io/qt-6/qml-qtquick-dragevent.html" target="_blank" rel="noopener noreferrer nofollow ugc">drag event</a> argument, from which you can establish the source, e.g. the dragged object.</p>
<p dir="auto">Have in mind though, that a drop doesn't cause reparenting automatically. So technically, there is no <em>new</em> parent, unless the app sets it explicitly.</p>
]]></description><link>https://forum.qt.io/post/830533</link><guid isPermaLink="true">https://forum.qt.io/post/830533</guid><dc:creator><![CDATA[Axel Spoerl]]></dc:creator><pubDate>Sat, 16 Aug 2025 19:50:12 GMT</pubDate></item></channel></rss>