xub*_*tix 9 qt application-development qml
在 qml 文档中有一个拖放示例:
import QtQuick 2.0
Item {
width: 200; height: 200
DropArea {
x: 75; y: 75
width: 50; height: 50
onDropped: console.log("dropped")
onEntered: console.log("entered")
Rectangle {
anchors.fill: parent
color: "green"
visible: parent.containsDrag
}
}
Rectangle {
x: 10; y: 10
width: 20; height: 20
color: "red"
Drag.active: dragArea.drag.active
Drag.hotSpot.x: 10
Drag.hotSpot.y: 10
MouseArea {
id: dragArea
anchors.fill: parent
drag.target: parent
}
}
}
Run Code Online (Sandbox Code Playgroud)
我用“onDropped”和“onEntered”添加了两行。虽然通过拖动小矩形触发“onEntered”,但我无法使“onDropped”触发。
我该怎么做才能触发它?
Dav*_*lla 15
显然需要通过调用Drag对象上的drop() 方法显式生成一个放置
尝试在 内添加这一行MouseArea,就在上面drag.target: parent
onReleased: parent.Drag.drop()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6038 次 |
| 最近记录: |