[Qt-interest] QGesture status in 4.6.3?
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Mon Jan 10 18:29:58 CET 2011
On 2011-01-10 ITS-CMT-SL-SFR-FIN-DEV Knoll Oliver, ITS-CMT-SL-SFR-FIN-DEV wrote:
> ...
> With QGraphicsPixmapItems in the scene, when handling the Gesture within the
> QGraphicsScene (derived class thereof) I receive proper QGestureEvents (Pan,
> Pinch) - but only as long as the mouse is not placed over any of my
> QGraphicsPixmapItems: it seems that the Pan gesture is "swallowed" once the
> mouse cursor is placed over the item: I do get the "Begin" state of the Pan
> Gesture, but no events thereafter.
> ...
> I opened a Qt issue with example code which reproduces this behaviour:
> http://bugreports.qt.nokia.com/browse/QTBUG-16281
The solution of this issue has been found: http://bugreports.qt.nokia.com/browse/QTBUG-16281
The thing to take extra care is that in your event handler you could be dealing with *multiple gestures* at the same time (in case your item grabs several of them, as in my case).
So *don't* do the "traditional" event handling pattern inside QGraphicsScene#gestureEvent(const QGestureEvent *event):
// WRONG!
if (swipe) {....}
else if (pan) {...}
else if (pinch) {...}
but instead:
// CORRECT:
if (swipe) {....}
if (pan) {...}
if (pinch) {...}
The reason is here: http://doc.qt.nokia.com/4.7/gestures-overview.html#handling-events: "As one target object can subscribe to more than one gesture type, the QGestureEvent can contain more than one QGesture, indicating several possible gestures are active at the same time. It is then up to the widget to determine how to handle those multiple gestures and choose if some should be canceled in favor of others."
I was mislead by the Qt example QTDIR/examples/gestures/imagegestures.cpp, which does some kind of "mix" between these "patterns" (and DOES work on my Mac! But it is QWidget based, without item hierarchy etc.).
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list