我使用MultiPointTouchArea来设计我自己的键盘,它可以用我的手指移动。但有一个问题让我困扰了几天。 在QT文档中,它说当我们在MultiPointTouchArea中使用MultiPointTouchArea时,我们应该有一个onGestureStarted()来获取我们需要的TouchPoint。 但是当我运行代码时,问题出现了。
import QtQuick 2.0
import QtQuick.Window 2.2
Window {
visible: true
width:3600
height:3600
MultiPointTouchArea
{
onGestureStarted: { gesture.grab();}
anchors.fill:parent
minimumTouchPoints: 8
mouseEnabled: true
id:test1
Image {
id: rocket
fillMode: Image.TileHorizontally
smooth: true
//source: 'file:///home/v/Desktop/KeyBroad_1024.jpg'
}
touchPoints:[
TouchPoint{id:point1},
TouchPoint{id:point2},
TouchPoint{id:point3},
TouchPoint{id:point4},
TouchPoint{id:point5},
TouchPoint{id:point6},
TouchPoint{id:point7},
TouchPoint{id:point8}//,
//TouchPoint{id:point9},
//TouchPoint{id:point10}
//function GAL(point1.x){}
]//fnction GAL(point1,point2){if(point1.x<point2.x) }
Rectangle {
width: 40; height: 40
color: "blue"
id:me11
x: point1.x
y: point1.y
Text {
text: qsTr("1")
}}
Rectangle {
width: 40; height: 40
color: "blue"
id:me12
x: point2.x
y: point2.y
Text {
text: qsTr("2")
}
MultiPointTouchArea{
anchors.fill:parent;
property color color_press: "lightgray"
property color color_release: "white"
onPressed: {
parent.color = color_press;
xPort.send(modifiersKey, message, 1);
}
onReleased: {
parent.color = color_release;
xPort.send(modifiersKey, message, 0);
}}
}
Rectangle {
width: 40; height: 40
color: "blue"
id:me13
x: point3.x
y: point3.y
Text {
text: qsTr("3")
}MultiPointTouchArea{
anchors.fill:parent;
property color color_press: "lightgray"
property color color_release: "white"
onPressed: {
parent.color = color_press;
xPort.send(modifiersKey, message, 1);
}
onReleased: {
parent.color = color_release;
xPort.send(modifiersKey, message, 0);
}}
}
Rectangle {
width: 40; height: 40
color: "blue"
id:me14
x: point4.x
y: point4.y
Text {
text: qsTr("4")
}MultiPointTouchArea{
anchors.fill:parent;
property color color_press: "lightgray"
property color color_release: "white"
onPressed: {
parent.color = color_press;
xPort.send(modifiersKey, message, 1);
}
onReleased: {
parent.color = color_release;
xPort.send(modifiersKey, message, 0);
}}}
Rectangle {
width: 40; height: 40
color: "blue"
id:me15
x: point5.x
y: point5.y
Text {
text: qsTr("5")
}
MultiPointTouchArea{
anchors.fill:parent;
property color color_press: "lightgray"
property color color_release: "white"
onPressed: {
parent.color = color_press;
xPort.send(modifiersKey, message, 1);
}
onReleased: {
parent.color = color_release;
xPort.send(modifiersKey, message, 0);
}} }
Rectangle {
width: 40; height: 40
color: "blue"
id:me16
x: point6.x
y: point6.y
Text {
text: qsTr("6")
}
MultiPointTouchArea{
anchors.fill:parent;
property color color_press: "lightgray"
property color color_release: "white"
onPressed: {
parent.color = color_press;
xPort.send(modifiersKey, message, 1);
}
onReleased: {
parent.color = color_release;
xPort.send(modifiersKey, message, 0);
}} }
Rectangle {
width: 40; height: 40
color: "blue"
id:me17
x: point7.x
y: point7.y
Text {
text: qsTr("7")
}
MultiPointTouchArea{
anchors.fill:parent;
property color color_press: "lightgray"
property color color_release: "white"
onPressed: {
parent.color = color_press;
xPort.send(modifiersKey, message, 1);
}
onReleased: {
parent.color = color_release;
xPort.send(modifiersKey, message, 0);
}}}
Rectangle {
width: 40; height: 40
color: "blue"
id:me18
x: point8.x
y: point8.y
Text {
text: qsTr("8")
}
MultiPointTouchArea{
anchors.fill:parent;
property color color_press: "lightgray"
property color color_release: "white"
onPressed: {
parent.color = color_press;
xPort.send(modifiersKey, message, 1);
}
onReleased: {
parent.color = color_release;
xPort.send(modifiersKey, message, 0);
}}}
}
}
它无法像我设置的那样获取文件。 例如,我用左手的小指将手指放在左手的食指上,右手的食指放到小指上。在窗口中它应该是1-2-3-4-5-6-7-8。但是当minimumTouchPoints =时8,有时它不起作用,有时它的工作方式不对(如5-2-3-4-1-6-7-8) 我需要MultiPoint来创建按钮,所以这里有问题 1,我该怎么办? 2,有没有其他方法可以实现我的目标:创建一个keyborad,然后它可以作为一个真正的键盘工作 谢谢你的回答。