Qt QML:Flickable的acceptedButtons
我有一个Flickable,其中有些内容有自己的Qt QML:Flickable的acceptedButtons,qt,event-handling,qml,mouseevent,Qt,Event Handling,Qml,Mouseevent,我有一个Flickable,其中有些内容有自己的DragHandler 我希望所有使用鼠标左键的拖动都由内容的拖动处理程序处理,而使用鼠标右键的拖动则应由Flickable处理。可能吗 示例代码: Flickable { id: canvas anchors.fill: parent contentWidth: 2*parent.width contentHeight: 2*parent.height // Something like this
DragHandler
我希望所有使用鼠标左键的拖动都由内容的拖动处理程序处理,而使用鼠标右键的拖动则应由Flickable处理。可能吗 示例代码:
Flickable {
id: canvas
anchors.fill: parent
contentWidth: 2*parent.width
contentHeight: 2*parent.height
// Something like this
//acceptedButtons: Qt.RightButton
Rectangle {
color: "blue"
width: canvas.width
height: canvas.height
DragHandler {
acceptedButtons: Qt.LeftButton
target: null
onActiveChanged: console.log(`content drag active: ${active}`)
// Some code to do something with the drag...
}
Rectangle {
color: "yellow"
anchors.centerIn: parent
width: 50
height: 50
}
}
}
目标:我想用鼠标右键拖动,将蓝色的矩形
移动到Flickable
中,而用鼠标左键拖动事件则由蓝色矩形
的拖动者处理,我发现接受的按钮静态设置为左按钮:
272:q->setAcceptedMouseButtons(Qt::LeftButton)
因此,我尝试通过引入另一个对我有效的DragHandler
来解决这个问题:
Flickable {
id: canvas
anchors.fill: parent
contentWidth: 2*parent.width
contentHeight: 2*parent.height
DragHandler {
property real _startX
property real _startY
acceptedButtons: Qt.RightButton
dragThreshold: 0
target: null
onActiveChanged: {
if (active) {
_startX = canvas.contentX
_startY = canvas.contentY
}
}
onTranslationChanged: {
canvas.contentX = _startX - translation.x
canvas.contentY = _startY - translation.y
}
}
Rectangle {
color: "blue"
width: canvas.width
height: canvas.height
DragHandler {
acceptedButtons: Qt.LeftButton
target: null
onActiveChanged: console.log(`content drag active: ${active}`)
// Some code to do something with the drag...
}
Rectangle {
color: "yellow"
anchors.centerIn: parent
width: 50
height: 50
}
}
}
它只是模仿标准行为,但允许使用DragHandler
的acceptedButtons
属性,用我想要的按钮控制Flickable
。
到目前为止,我没有注意到Flickable
的任何其他行为突破了这个解决方案