Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. StackLayout detect drag from a component outside itself
Qt 6.11 is out! See what's new in the release blog

StackLayout detect drag from a component outside itself

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 348 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chilarai
    wrote on last edited by
    #1

    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 Droparea (third one is dynamically created) where I want to drag items from a Listview which is outside the StackLayout. Is it possible or I am doing something wrong?

    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
    
                }
            }
        }
    }
    
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved