cursorShape
我想在将项目拖出时不断更改MouseArea
。
正如您在下面的代码中看到的,当我将鼠标保持在 current 时MouseArea
,cursorShape
将更改为DragCopyCursor
. 但是,进一步,如果我将鼠标移动到另一个 mouseArea 区域,鼠标将ArrowCursor
再次变为。
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
color: "#aaaaaa"
width: 300
height: 50
MouseArea {
id: mouseArea
anchors.fill: parent
drag.target: rec
Binding {
when: mouseArea.drag.active
mouseArea.cursorShape: Qt.DragCopyCursor
}
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
}
}
]
}
}
}
}
}
}
如果你使用
DragHandler
而不是MouseArea
你可以cursorShape
在整个拖动过程中保持你的状态。注意,为了DragHandler
工作,我必须用x
和的显式计算来替换锚定y
: