QML:即使drag属性处于活动状态,也不会调用onDragStarted / finish [英] QML: onDragStarted / finished not called even though the drag property is active
问题描述
在下面的示例中,我希望拖动一个矩形时调用 onDragStarted
/ onDragFinished
。但是,仅 Drag.onActiveChanged
被调用。将 Drag.dragType
设置为 Drag.Automatic
时,我得到了预期的输出,但是我再也看不到矩形了。我在Mac(El Capitan)上使用Qt 5.5。
In the following example I would expect that onDragStarted
/ onDragFinished
are called when one rectangle is dragged. However only drag.onActiveChanged
(of the mouseArea) and Drag.onActiveChanged
(of the rectangle are called). I get the expected output when setting Drag.dragType
to Drag.Automatic
but then I don't see the rectangle anymore. I am using Qt 5.5 on a Mac (El Capitan).
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
visible: true
width: 100
height: 200
ListModel {
id: testModel
ListElement { name: "red"; value: "#f00" }
ListElement { name: "green"; value: "#0f0" }
ListElement { name: "blue"; value: "#00f" }
}
Component {
id: rect
Rectangle {
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: width / 2
Drag.hotSpot.y: height / 2
//Drag.dragType: Drag.Automatic
Drag.onActiveChanged: {
console.log("Active changed..")
}
Drag.onDragStarted: {
console.log("Drag started..")
}
Drag.onDragFinished: {
console.log("Drag finished!")
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
drag.target: parent
drag.onActiveChanged: {
console.log("Drag prop became active..")
}
onClicked: {
colorButtonClicked(buttonName, buttonColor);
}
}
width: 80
height: 20
radius: 6
color: model.value
}
}
Column {
spacing: 3
anchors.centerIn: parent
Repeater {
model: testModel
delegate: rect
}
}
}
推荐答案
基于信号名称的假设,我对相同的问题感到困惑,但请查看文档显示,只有在使用 Drag.Automatic
或显式调用 startDrag
。
I was puzzled about the same problem based on my assumptions from the signal names, but a look at the documentation showed that the signals will only work when using Drag.Automatic
or explicitly calling startDrag
.
dragStarted()
在拖动时发出此信号
dragStarted()
This signal is emitted when a drag is started with the startDrag() method or when it is started automatically using the dragType property.
此信号在发出该信号时发出拖动完成,并且拖动使用startDrag()方法启动,或者使用dragType属性自动开始。
This signal is emitted when a drag finishes and the drag was started with the startDrag() method or started automatically using the dragType property.
使用<$ c时出现的另一个问题$ c> Drag.Automatic 在Qt 5.6.1中似乎已修复
The other issue seen when using Drag.Automatic
appears to be fixed in Qt 5.6.1
这篇关于QML:即使drag属性处于活动状态,也不会调用onDragStarted / finish的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!