我有Qt5.10,为Raspberry Pi3交叉编译
我有一个基于 QML 的程序,我可以在其中捕获鼠标滚轮事件并执行一些功能!
我想将另一只鼠标连接到我的树莓派。所以每个鼠标在我的程序中都会有不同的功能!!
如何区分这两种鼠标设备?
例如,我可以获取每个鼠标 ID 并采取相应行动吗?
使用MultiPointTouchArea
您可以将 2 只鼠标作为单独的touchPoints
处理。
但是,您可以处理的操作将受到限制。但是使用pressed
、released
和touchUpdated
信号,您可以轻松处理点击/拖动事件:
MultiPointTouchArea {
mouseEnabled: true
touchPoints: [
// your 2 recognizable touchPoints for your 2 mice
TouchPoint { id: point1 },
TouchPoint { id: point2 }
]
onPressed: {
touchPoints.forEach(function(touchPoint) {
if (touchPoint === point1) {
console.log("FIRST MOUSE PRESSED:", touchPoint.x, touchPoint.y)
} else if (touchPoint === point2){
console.log("SECOND MOUSE PRESSED:", touchPoint.x, touchPoint.y)
}
})
}
onReleased: {
touchPoints.forEach(function(touchPoint) {
if (touchPoint === point1) {
console.log("FIRST MOUSE RELEASED:", touchPoint.x, touchPoint.y)
} else if (touchPoint === point2){
console.log("SECOND MOUSE RELEASED:", touchPoint.x, touchPoint.y)
}
})
}
onTouchUpdated: {
touchPoints.forEach(function(touchPoint) {
if (touchPoint === point1) {
console.log("FIRST MOUSE UPDATED:", touchPoint.x, touchPoint.y)
} else if (touchPoint === point2){
console.log("SECOND MOUSE UPDATED:", touchPoint.x, touchPoint.y)
}
})
}
}
输出(仅使用单个鼠标测试,但它应该使用 2(:
qml: FIRST MOUSE PRESSED: 418 326
qml: FIRST MOUSE UPDATED: 419 327
qml: FIRST MOUSE UPDATED: 420 327
qml: FIRST MOUSE UPDATED: 421 327
qml: FIRST MOUSE UPDATED: 422 328
qml: FIRST MOUSE UPDATED: 423 328
qml: FIRST MOUSE UPDATED: 424 329
qml: FIRST MOUSE UPDATED: 425 329
qml: FIRST MOUSE UPDATED: 426 329
qml: FIRST MOUSE UPDATED: 427 329
qml: FIRST MOUSE RELEASED: 427 329
不幸的是,我想不出另一种能够捕获多个悬停/车轮事件的解决方案。