Qt,手势.无法识别TapAndHold和Swipe [英] Qt, Gestures. TapAndHold and Swipe are not recognized

查看:204
本文介绍了Qt,手势.无法识别TapAndHold和Swipe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了 http://doc.qt的图像手势示例" .digia.com/4.6/gestures-imagegestures.html .在此示例中,您只有3个手势:PanGesture,PinchGesture和SwipeGesture.但是Qt提供了5种手势:

I tried a "Image Gestures Example" from http://doc.qt.digia.com/4.6/gestures-imagegestures.html. In this Example you have only 3 Gesture: PanGesture, PinchGesture and SwipeGesture. But Qt provides 5 Gestures:

  • TapGesture
  • TapAndHoldGesture
  • PanGesture
  • PinchGesture
  • SwipeGesture

为了识别所有5种手势,我们需要将其写入ImageWidget-Constructor:

In order to recognize all 5 gestures we need to write into ImageWidget-Constructor:

 grabGesture(Qt::TapGesture);
 grabGesture(Qt::TapAndHoldGesture);
 grabGesture(Qt::PanGesture);
 grabGesture(Qt::PinchGesture);
 grabGesture(Qt::SwipeGesture);

我还添加了方法gestureEvent()

i added the method gestureEvent() also

bool ImageWidget::gestureEvent(QGestureEvent *event)
 {
     if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
         swipeTriggered(static_cast<QSwipeGesture *>(swipe));
     else if (QGesture *pan = event->gesture(Qt::PanGesture))
         panTriggered(static_cast<QPanGesture *>(pan));
     if (QGesture *pinch = event->gesture(Qt::PinchGesture))
         pinchTriggered(static_cast<QPinchGesture *>(pinch));
     if (QGesture *tap = event->gesture(Qt::TapGesture))
         tapTriggered(static_cast<QTapGesture *>(tap));
     if (QGesture *tapandhold = event->gesture(Qt::TapAndHoldGesture))
     {
         tapandholdTriggered(static_cast<QTapAndHoldGesture *>(tapandhold));
      }
     return true;
 }

并编写缺少的方法,例如

and write missing methods like

void ImageWidget::tapTriggered(QTapGesture *gesture)
 {
    qDebug() << "TAP" << gesture->position();
 }

 void ImageWidget::tapandholdTriggered(QTapAndHoldGesture *tapandhold)
 {
     qDebug() << "TAPANDHOLD";
 }

所以,我的问题是,为什么不识别手势Swipe和TapAndHold? 这些手势等效地实现为可识别的三个手势(平底锅",捏"和敲击").为什么不起作用?

so, my Question is, why gestures Swipe and TapAndHold are not recognized? These gestures are equally implemented as three gestures that are recognized (Pan, Pinch and Tap). Why it does not work?

感谢您的帮助

推荐答案

同样,如果您描述平台和触摸硬件,也会有所帮助.

Again, it would help if you describe your platform and touch hardware.

在OSX,Qt5,PyQt上,使用Apple TouchPad,我发现除非您接受QGestureOverride类型的QEvent,否则某些手势事件不会到达.有关此类事件目的的文档非常模糊.该文档确实说默认情况下会忽略它,这是一个例外:默认情况下会接受大多数其他手势,这意味着相同手势的进一步事件将会到来.

On OSX, Qt5, PyQt, using an Apple TouchPad, I found that certain gesture events did not arrive unless you accept the QEvent of type QGestureOverride. The documentation is very fuzzy about the purpose of such an event. The documentation does say that is is ignored by default, which is exceptional: most other gestures are accepted by default, which means that further events for the same gesture will come.

手势的接受"的含义不同于事件的接受"的一般含义. 接受"手势似乎意味着让更多事件来临",而接受"事件意味着不要通过小部件链传播该事件".此外,文档对于接受QGestureEvent与接受QGesture感到非常困惑. QGestureEvent是QGestures的组合.接受QGestureEvent是否与接受包含的手势相同,这非常令人困惑.请注意,QGesture不具有accept()方法,QGestureEvent具有多个重载和便捷方法:accept(),setAccepted(bool),setAccepted(gesture,bool),setAccepted(gestureType,bool)等.

This meaning of "accept" for gestures is different from the general meaning of "accept" for events. "Accept" a gesture seems to mean "let further events come" while "accept" an event means "don't propagate this event thru the chain of widgets." Also, the docs are very confusing about accepting a QGestureEvent versus accepting a QGesture. A QGestureEvent is a composite of QGestures. It is very confusing whether accepting a QGestureEvent is the same as accepting the contained gestures. Note that QGesture does not have an accept() method, and QGestureEvent has several overloaded and convenience methods: accept(), setAccepted(bool), setAccepted(gesture, bool), setAccepted(gestureType, bool), etc.

返回到QGestureOverride类型的QEvent:Qt.QEvent枚举显示"Qt.QGestureOverride ...(QGestureEvent)",对我来说,这意味着QGestureOverride类型的事件是QGestureEvent的子类,但不是:没有:没有QGestureOverride类型的事件上的gestures()方法. (因此,如何知道您接受的是哪种手势替代呢?)似乎是这样的情况:忽略事件的默认值不仅是允许其传播,而且还防止包含的(单个)手势发生后续事件(不管他们是什么.)

Back to QEvent of type QGestureOverride: the Qt.QEvent enumeration shows "Qt.QGestureOverride ...(QGestureEvent)" which to me means an event of type QGestureOverride is a subclass of QGestureEvent, but it is not: there is no gestures() method on an event of type QGestureOverride. (So how does one know what kind of gesture override you are accepting?) And it seems to be the case that the default of ignoring the event is not just allowing it to propagate, but preventing subsequent events for the contained (sic) gestures (whatever they are.)

例如,在我的某些测试中,真正的两指捏法从来没有生成具有Pinch类型的手势的手势事件,而是生成了Pan类型的手势事件,直到我接受QGestureOverride类型的QEvent为止.然后,当我捏捏时或捏捏后,我不小心平移了两个手指时,先是出现了捏捏手势事件,然后是捏捏和平移手势事件. (请注意,至少在OSX TrackPad上,用两个手指平移(滚动操作)是由设备驱动程序或控制面板定义的,是两个手指吗?)

For example, in some of my testing, a real, two-finger pinch never generated any gesture events having a gesture of type Pinch, but did generate of type Pan, until I accepted the QEvent of type QGestureOverride. Then, the Pinch gesture events came first, and later both Pinch and Pan gesture events, when I sloppily panned my two fingers as I pinched, or after I pinched. (Note at least on OSX TrackPad, a Pan (a scroll operation) is with two fingers, as defined by the device driver or control panel for same?)

这篇关于Qt,手势.无法识别TapAndHold和Swipe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆