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:
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);
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";
}
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?
I thank you advance for the help
Again, it would help if you describe your platform and touch hardware.
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.
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.
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.)
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?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With