Thanks for @folibis's help in comment, here is the answer for my quesiont.
For anyone who has the same problem as me, you just need to specify a larger z
for delegate
whose drag.active
of MouseArea
is true
.
import QtQuick
import QtQuick.Controls
Window {
width: 300
height: 300
visible: true
color: "#1F1F1F"
Column {
anchors.centerIn: parent
Repeater {
model: 2
delegate: Rectangle {
z: mouseArea.drag.active ? 2 : 0 // key
color: "#aaaaaa"
width: 300
height: 50
MouseArea {
id: mouseArea
anchors.fill: parent
drag.target: rec
Rectangle {
id: rec
color: "white"
height: parent.height / 2
width: parent.width / 2
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
Text {
anchors.centerIn: parent
text: "test " + index
color: "black"
}
states: [
State {
when: mouseArea.drag.active
AnchorChanges {
target: rec
anchors.verticalCenter: undefined
anchors.horizontalCenter: undefined
}
}
]
}
}
}
}
}
}
This is a screenshot of running the above code:
