gpt4 book ai didi

drag-and-drop - QML:即使拖动属性处于事件状态,也未调用 onDragStarted/finished

转载 作者:行者123 更新时间:2023-12-03 16:27:31 25 4
gpt4 key购买 nike

在下面的例子中,我希望 onDragStarted/onDragFinished当拖动一个矩形时调用。然而只有drag.onActiveChanged (鼠标区域的)和 Drag.onActiveChanged (矩形的称为)。设置 Drag.dragType 时我得到了预期的输出至 Drag.Automatic但后来我再也看不到矩形了。我在 Mac (El Capitan) 上使用 Qt 5.5。

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
}
}
}

最佳答案

基于我对信号名称的假设,我对同样的问题感到困惑,但看看 documentation表明信号仅在使用 Drag.Automatic 时有效或明确调用 startDrag .

dragStarted()

This signal is emitted when a drag is started with the startDrag() method or when it is started automatically using the dragType property.

dragFinished(DropAction action)

This signal is emitted when a drag finishes and the drag was started with the startDrag() method or started automatically using the dragType property.


使用 Drag.Automatic 时遇到的另一个问题似乎已在 Qt 5.6.1 中修复

关于drag-and-drop - QML:即使拖动属性处于事件状态,也未调用 onDragStarted/finished,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34158899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com