<?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[StackLayout detect drag from a component outside itself]]></title><description><![CDATA[<p dir="auto">I have a StackLayout with 3 stack items (2 static and one dynamically generated) which switches on button click. I want to make the second and third stack items a <code>Droparea</code> (third one is dynamically created) where I want to drag items from a <code>Listview</code> which is outside the StackLayout. Is it possible or I am doing something wrong?</p>
<pre><code>import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

Page{
    id: pageid
    width: parent.width
    height: parent.height

    Row{
        id: row1

        Button{
            text: "0"
            onClicked: layout.currentIndex = 0
        }
        Button{
            text: "1"
            onClicked: layout.currentIndex = 1
        }
        Button{
            text: "2"
            onClicked:{
                var str = 'import QtQuick 2.15; Rectangle {id: rect2; color: "red"; DropArea{anchors.fill: parent; onEntered: {rect2.color = "silver"}}}'
                var comp = Qt.createQmlObject(str,layout,"dynamicSnippet1")
                onClicked: layout.currentIndex = 2
            }
        }
    }

    // Stacklayout block
    StackLayout {
        id: layout
        anchors.top: row1.bottom
        height: parent.height - row1.height - dragger.height
        width: parent.width
        currentIndex: 0

        // Component 0
        Rectangle {
            id: rect0
            color: 'teal'
        }

        // Component 1
        Rectangle {
            id:rect1
            color: 'plum'

            DropArea{
                anchors.fill: parent
                onEntered: {rect1.color = "gold"}

            }
        }
    }



    // Drag rectangles
    ListView{
        id: dragger
        anchors.top: layout.bottom
        height: 30
        width: parent.width
        orientation: Qt.Horizontal
        model: 3
        delegate:  Rectangle{
            id: xrect
            height: 30
            width: 60
            color:"grey"
            border.width: 1
            border.color: "orange"

            MouseArea{
                id: ma
                anchors.fill: parent
                onReleased: parent.Drag.drop()
                drag.target: parent

            }
        }
    }
}

</code></pre>
]]></description><link>https://forum.qt.io/topic/120037/stacklayout-detect-drag-from-a-component-outside-itself</link><generator>RSS for Node</generator><lastBuildDate>Tue, 04 Aug 2026 15:34:28 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/120037.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 17 Oct 2020 07:07:57 GMT</pubDate><ttl>60</ttl></channel></rss>