我正在这样检测Qt应用程序上的触摸手势:
void CameraController::handleTouch(QTouchEvent *event)
{
/*
* Just 2 fingers on touch screen
*/
if (event->touchPoints().length() == 2) {
QTouchEvent::TouchPoint point1 = event->touchPoints().at(0);
QTouchEvent::TouchPoint point2 = event->touchPoints().at(1);
/*
* Both fingers are "moving"
*/
if (point1.state() == Qt::TouchPointMoved &&
point2.state() == Qt::TouchPointMoved) {
qDebug() << __func__ << "Gesture: 2-fingers!";
handleGesture2fingers(point1, point2);
}
}
/*
* Only 1 finger on touch screen
*/
} else if (event->touchPoints().length() == 1) {
QTouchEvent::TouchPoint point = event->touchPoints().at(0);
/*
* The finger is moving
*/
switch (point.state()) {
case Qt::TouchPointMoved:
qDebug() << __func__ << "Gesture: single finger!";
handleGestureSingleFinger(point);
break;
default:
break;
}
/*
* Three fingers on touch screen
*/
} else if (event->touchPoints().length() == 3) {
QTouchEvent::TouchPoint point1 = event->touchPoints().at(0);
QTouchEvent::TouchPoint point2 = event->touchPoints().at(1);
QTouchEvent::TouchPoint point3 = event->touchPoints().at(2);
/*
* All 3 fingers are moving
*/
if (point1.state() == Qt::TouchPointMoved &&
point2.state() == Qt::TouchPointMoved &&
point3.state() == Qt::TouchPointMoved) {
qDebug() << __func__ << "Gesture: 3-fingers!";
handleGesture3fingers(point1, point2, point3);
}
}
}
令我惊讶的是,正如我的日志显示的那样,我的手势彼此干扰,2-finger
手势与3-finger
手势干扰:
handleTouch Gesture: 2-fingers!
handleTouch Gesture: 2-fingers!
handleTouch Gesture: 3-fingers!
handleTouch Gesture: 3-fingers!
handleTouch Gesture: 3-fingers!
handleTouch Gesture: 3-fingers!
handleTouch Gesture: 2-fingers!
handleTouch Gesture: 2-fingers!
还有single-finger
个手势干扰了2-finger
手势:
handleTouch Gesture: 2-fingers!
handleTouch Gesture: 2-fingers!
handleTouch Gesture: 2-fingers!
handleTouch Gesture: single finger!
handleTouch Gesture: single finger!
handleTouch Gesture: 2-fingers!
handleTouch Gesture: single finger!
handleTouch Gesture: 2-fingers!
handleTouch Gesture: single finger!
handleTouch Gesture: 2-fingers!
handleTouch Gesture: 2-fingers!
handleTouch Gesture: single finger!
handleTouch Gesture: 2-fingers!
干扰会对用户体验产生负面影响。我不知道如何避免这些手势干扰。
我没有更改代码,但是今天我发现应用程序运行良好,用户体验也很好!也许我昨天使用的触摸屏设备不可靠:)