我使用QtQuick,我制作了一个能够拖放项目的QML项目 .

我正在尝试为拖放功能添加规则: You cannot drop your item between two specified items .

为了解释我的问题,项目将是矩形 .

例如:

规则: You are not allowed to move a rectangle between the rectangle 2 and the rectangle 3 .

在这种情况下,当我需要移动其中一个时,我试图移动矩形2和3 at the same time . 但我不能成功,只有一个被感动 .

Here is an example

Rectangle {
    visible: true
    width: 1000; height: 1000
    ListView {
        id: root
        width: parent.width; height: parent.height

        model: DelegateModel {

            id: visualModel
            model: myModel
            model: ListModel {
                id: colorModel
                ListElement { someData }
                ...

            }

            delegate: MouseArea {

                property int visualIndex: DelegateModel.itemsIndex

                id: delegateRoot
                cursorShape: Qt.PointingHandCursor
                width: root.width; height: 100
                drag.target: icon
                drag.axis: Drag.YAxis
                drag.minimumY: 0

                Rectangle {
                  blablaData

                }

//IMPORTANT PART

                DropArea {
                    anchors { fill: parent; margins: 15 }

                    onEntered: {
                        if(drag.source.visualIndex <delegateRoot.visualIndex ) { //Only when my item is going down, I didn't implement the "up move"
                            if(drag.source.visualIndex==2) {
                                visualModel.items.move(drag.source.visualIndex, delegateRoot.visualIndex,2) //This is where I try to move two items at the same time, not working
                            }
                            else if(drag.source.visualIndex==3) {
                            //Do nothing, already moved when it was rectangle 2
                            }
                            else {
                               visualModel.items.move(drag.source.visualIndex, delegateRoot.visualIndex)
                            }
                        }
                    }
               }
          }
    }
}

你知道我做错了什么吗?

非常感谢 !