重写bool event(QEvent *event)接口
bool event(QEvent *event)
{
if (event->type() == QEvent::Gesture)
return gestureEvent(static_cast<QGestureEvent*>(event));
return QWidget::event(event);
}
手势事件处理函数
bool gestureEvent(QGestureEvent *event)
{
if (QGesture *tap = event->gesture(Qt::TapGesture))
tapTriggered(static_cast<QTapGesture *>(tap));
return true;
}
单击手势事件处理函数
void tapTriggered(QTapGesture *gesture)
{
if(Qt::GestureFinished == gesture->state())
{
qDebug() <<"tapTriggered: "<<gesture->position();
}
}