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. Drag and dropping identical QML components on top of each other
Qt 6.11 is out! See what's new in the release blog

Drag and dropping identical QML components on top of each other

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 314 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.
  • NihilishN Offline
    NihilishN Offline
    Nihilish
    wrote on last edited by
    #1

    Hi,

    I have a repeater that generates a bunch of rectangles. I want to be able to drag these rectangles around and generate an event when I drop one rectangle on another (think files and folders on an OS. I can drag folders & files, but I can drop a file on a folder and it stores it inside). I've tried the following but the dropArea gets confused because the object itself is draggable. OnDropped just never triggers. Is this possible?

    Repeater {
                model: 5
                Item {
                    id: element
    
                    Item {
                        id: surfaceContainer
    
                        width: 150
                        height: 150
                        x: index * width
    
                        DropArea {
                            id: dropArea
    
                            anchors.fill: surfaceContainer
    
                            onContainsDragChanged: {
                                if (containsDrag && drag.source != draggableRectangle)
                                    console.log("CHANGED")
                            }
    
                            onEntered: {
                                if (drag.source != draggableRectangle)
                                    console.log("ENTERED")
                            }
    
                            onDropped: {
                                console.log("DROPPED")
                            }
    
                            onExited: {
                                if (drag.source != draggableRectangle && containsDrag)
                                    drag.source.color = "yellow"
                            }
                        }
    
                        Rectangle {
                            id: draggableRectangle
    
                            x: width / 2
    
                            color: "blue"
                            height: 100
                            width: 100
    
                            Drag.active: dragArea.drag.active
    
                            MouseArea {
                                id: dragArea
    
                                anchors.fill: draggableRectangle
                                drag.target: draggableRectangle
    
                                onDoubleClicked: {
                                    connectionId.visible = !connectionId.visible
                                }
                            }
                        }
                    }
                }
            }
    
    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