PDA

View Full Version : How to set Qt::GestureType for my specific gesture?



GreenScape
10th October 2011, 17:58
Title says pretty much what i need. Can't find the way to recognize 2 different user defined gestures. What am i doing wrong? The only useful resource i found so far was this (http://www.developer.nokia.com/Community/Wiki/Custom_Swipe_Gestures_in_Qt) link.

Thank You.

wysota
10th October 2011, 21:07
QGestureRecognizer::registerRecognizer() returns a value that can be used as Qt::GestureType. Be sure to carefully read the docs for Qt::GestureType!

GreenScape
11th October 2011, 07:11
Thank you very much! That's exactly what I was looking for. I haven't read carefully I guess :|

bootchk
16th April 2012, 14:01
I am also trying to implement a custom gesture, with a custom gesture object inheriting QGesture.

If registerRecognizer() returns a gesture type ID, then should that be passed to grabGesture(gestureTypeID) ? One example showed the grabGesture() call before the registerRecogizer() call. Possibly that example was wrong, or possibly it only works when the gesture type is a built-in gesture. (The example shows how to reimplement QPanGesture to fix a non-working version on some platforms.)

My understanding of the sequence: calling registerRecognizer() invokes the create() method of the recognizer, which creates a gesture of a certain class (in this case a custom gesture). The document says the ID is "generated" which means it is somewhat arbitrary for custom gestures (a bitwise OR of QCustomGesture and other arbitrary bit)? I assume that the gestureID is passed to the gesture constructor, otherwise, how would it know? So, a custom gesture should not reimplement the gestureType() method, that should all be hidden? A call to gestureType() will return the ID assigned to the gesture when it is created() by the recognizer?

But the rest of your application (the gestureEvent handlers) needs to know the gesture ID, so when it is returned by registerRecognizer() the app should store it in a global variable? It is not defined at compile time.

This is all speculative. Currently my Python Pyside Qt code is crashing in the gestureType() method of my custom gesture (whether I reimplement it or not, and whether my custom gesture inherits from QGesture or QPanGesture) ! I am installing Qt 4.8 to insure it is not a bug already fixed.

I am also confused about the "parent" parameter of a QGesture constructor. I presume it is a parent Widget. It defaults to None, which is the case when a gesture instance is first created when registerRecognizer is called? I presume later, on the call to grabGesture() the Qt framework changes the parent property to be the widget that is grabbing. Or later, when a raw input event is in a widget that has grabbed a gesture, the framework sets the parent of the gesture?

The Qt documentation is rather good, but very abstract and subtle: you must read it carefully. So far it is eluding me. It is a good thing the source is open.