【发布时间】:2017-12-12 13:41:06
【问题描述】:
我正在尝试完成一个简单的图像拖动,当拖动完成或开始时触发一个事件。
Rectangle {
id: upperFooter
color: "transparent"
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
Drag.onDragFinished: onDragFinished()
Drag.dragType: Drag.Automatic
width: 800
height: 40
Image {
height: 40
width: upperFooter.width
source: "qrc:///images/footer/background_footer.svg"
MouseArea {
id: iconMouseArea
x: 390
y: 10
anchors.fill: parent
onClicked: toggleHiddenBar()
drag {
target: upperFooter
axis: Drag.YAxis
}
}
}
upperFooter 项上的事件不会触发。
QML: onDragStarted / finished not called even though the drag property is active --> 我已尝试将 Drag.type 放在 Drag.Automatic 上以解决此问题,但仍然不起作用。
QtQuick v 2.6 布局 1.3 QML 5.6
【问题讨论】:
-
根据the documentation,您应该将 Drag.active 绑定到 MouseArea:使用 Drag.Automatic 时,您还应该定义 mimeData 并将 active 属性绑定到 MouseArea 的 active 属性: MouseArea: :drag.active
-
还有一点需要注意:您应该将
MouseArea放置为Rectangle的子代,而不是Image -
@folibis 我正在尝试但未能将您的建议应用于stackoverflow.com/a/38168103/13675,如果您能在此发表评论并在这种情况下提供必要代码的答案,我将不胜感激,我也许可以申请到那个案子。