PDA

View Full Version : TapAndHold gesture wrongly generated



maitai
2nd March 2014, 18:28
Hello,

I am having the following problem with tapAndHold gesture:

I have 2 QGraphicsItems in a QGraphicsScene. One of them have a Z-Value of 100, the other one has 90. Both of them are selectable. They also both grab tapGesture and tapAndHoldGesture.

I want to catch tapAndHoldGesture in order to display a contextual menu. That is working. If my 2 QGraphicsItems are not overlapping (i.e. their shape() are not overlapping), then I don't have any problem when I simply tap on one of the items (it becomes selected as it should). But when I do a simple tap on the item with 100 z-value and the item with 90 z-value is beneath, then after 10secs (I have specified QTapAndHoldTimeOut(10000) ), I get a unexpected tapAndHold event for the item I have tapped, although I am not touching the screen anymore.

Note that if I generate the tapAndHoldGesture with a long mouse click instead of a long tap on the screen, this problem does not appear and every thing behave as it should. The wrong tapAndHoldGesture is generated only after a short tap on the screen if items shapes are overlapping.

I have tested this behavior with both Android and Windows 7, using QT 5.2.1. It seems to me that in that case for some reason the tapAndHold gesture timer is not stopped.

With some qWarning() inside sceneEvent(), I can see that the sequence when I touch the top item is the following:
(item1 is the item in front of item2)

item1 202 (gestureOverride)
item2 202 (gestureOverride)
item1 198 (gesture - tapGesture with state()==GestureStarted)
item1 202 (gestureOverride)
item2 202 (gestureOverride)
item1 198 (gesture - tapGesture with state()==GestureStarted)
item2 194 (touch begin)
item1 186 (mouse move)
item1 186 (grab mouse)
item1 156 (mouse pressed)
item1 198 (gesture - tapGesture with state()==GestureFinished)
item1 157 (mouse released)
item1 197 (ungrab mouse)
item1 202 (gesture override)
item2 202 (gesture override)
item1 198 (gesture - tapAndHoldGesture with state()==GestureStarted)
item1 198 (gesture - tapAndHoldGesture with state()==GestureFinished)

I have tried a lot of various combinations of accepting/ignoring event or gesture or gestureOverride with no luck.

Finally what I did to turn around this problem is that I check that the item is the scene's mouse grabber and if this is not the case I ignore the tapAndHoldGesture. But this is a bad hack imo.

Should I fill a bug report? Maybe someone else has this kind of things working and I did something wrong?

Thanks
Philippe.

bootchk
26th June 2014, 19:52
I don't have it working and I have no experience with Tap or TapAndHold. But that does seem strange.

I looked at the code for those two recognizers. My understanding is: when the TapAndHold recognizer gets a TouchEnd or MouseRelease before its timer goes off, the gesture is canceled, and Qt will call the reset() method of the recognizer, which does stop the timer. In your sequence above, there IS a mouse release that should have canceled the T&H gesture (which was in the maybe state.)

Maybe it is a bug, a subtle condition that the designers didn't anticipate. It must be related to the overlapping, which is related to the GestureOverride, which I don't understand and which is not documented.

Have you tried setCancelPolicy(CancelAllInContext) when the Tap is recognized?