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. [SOLVED] Qt 6.2.2 - Drag & Drop broken in Quick?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Qt 6.2.2 - Drag & Drop broken in Quick?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 470 Views 1 Watching
  • 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.
  • H Offline
    H Offline
    Heals
    wrote on last edited by Heals
    #1

    [UPDATE]
    further research leads to a solution of which I'm not sure if it's a work-around or just how things should always have been. The whole issue is that Qt's code examples change the parent of the dragged object but never reset it to a proper delegate container inside the ListView / GridView.

    For Qt's own example this means changing this part in Icon.qml:

        states: [
            State {
                when: dragHandler.active
                ParentChange {
                    target: icon
                    parent: icon.dragParent
                }
    
                AnchorChanges {
                    target: icon
                    anchors.horizontalCenter: undefined
                    anchors.verticalCenter: undefined
                }
            }
        ]
    

    To look like this:

        states: [
            State {
                when: dragHandler.active
                ParentChange {
                    target: icon
                    parent: icon.dragParent
                }
    
                AnchorChanges {
                    target: icon
                    anchors.horizontalCenter: undefined
                    anchors.verticalCenter: undefined
                }
            },
            /* reparent the item to it's former delegateRoot parent */
            State {
                when: !dragHandler.active
                ParentChange {
                    target: icon
                    parent: delegateRoot
                }
                
                AnchorChanges {
                    target: icon
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.verticalCenter: parent.verticalCenter
                }
            }
        ]
    

    [ORIGINAL POST]

    I've recently been trying to implement Drag & Drop reordering of a simple ListView's items.
    Following the Quick samples was easy enough and everything is fine as long as the user drops an item in a new position (e.g. swaps places with another existing list item). However if the user cancels the drag for whatever reason then the dragged item will be randomly displaced inside the list view with no way to restore it's original position.

    I'm not sure if I'm doing something wrong or if this is a fundamental bug in how Quick handles Drag & Drop but it's reproducible in Qt's own samples as well (so it doesn't seem like my code is at fault):

    drag-cancel-bug.gif

    Has anyone encountered this behaviour / knows a fix or workaround for it?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TonyNguyen
      wrote on last edited by
      #2

      Thank you very much. I'm struggling a lot before I saw that post

      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