qt - 如何修复在拖动时切换按下的鼠标按钮时发生的卡住 QML 拖动
问题描述
我们遇到了当用户在拖动时切换按下的鼠标按钮时,在 QML 中拖动可能会卡住的问题。
我附上了一个最小的例子,它基本上是文档文档中给出的例子。
- 用鼠标左键开始拖动
- 除左键外按鼠标右键
- 松开鼠标左键(按住右键) 黄色矩形按预期快速回到原来的位置
- 仅按下鼠标右键继续拖动任何拖动在我们看来已经是一个错误,因为只有
Qt.LeftButton
被接受 - 释放鼠标右键 黄色矩形(大多数时候)停留在上次拖动的位置 这给我们带来了问题,因为我们的用户开始意外(和故意)破坏 UI
- 要修复黄色矩形位置,请在绿色区域内开始新的拖动
有人能够确认这种行为吗?
和/或能够暗示该问题的解决方案?
干杯托比
我们正在使用 Qt5.12.11
import QtQuick 2.5
Rectangle {
id: rootDialog
anchors.fill: parent
anchors.margins: 5
border.width: 1
color: "#11ffffff"
Rectangle {
id: root
color: "green"
property string colorKey: "yellow"
width: 64; height: 64
MouseArea {
id: mouseArea
width: 64; height: 64
anchors.centerIn: parent
drag.target: tile
onReleased: parent = tile.Drag.target !== null ? tile.Drag.target : root
acceptedButtons: Qt.LeftButton //we only want the dragging to happen with the left mouse button
Rectangle {
id: tile
width: 64; height: 64
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
color: root.colorKey
Drag.keys: [ root.colorKey ]
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: 32
Drag.hotSpot.y: 32
states: State {
when: mouseArea.drag.active
ParentChange { target: tile; parent: root }
AnchorChanges { target: tile; anchors.verticalCenter: undefined; anchors.horizontalCenter: undefined }
} //states
} //Rectangle
} //MouseArea
} //Rectangle
} //Rectangle
解决方案
推荐阅读
- macos - NSTextFieldCell drawWithFrame 中的 Cocoa 内存泄漏?
- coldfusion - ColdFusion 中 ROT13 上的幻数去除
- mysql - 如何检查两个值是否存在于两列中或不在mysql中?
- javascript - 为什么 map.fitBounds(group.getBounds()) 使用一组数据而不是另一组数据?
- algorithm - 算法问题:仅使用给定字典中的单词从给定单词到另一个单词的转换
- python - python3 linux - 用root检测键盘按键
- c# - 如何对绘制的图形进行操作
- ruby - 如何测试方法是否被调用
- html - 页脚外的文字
- android - 无法解析 ':app@debug/compileClasspath' 的依赖关系:无法解析 com.daimajia.slider:library:1.1.5