Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.
Handling Gestures in Qt
This article demonstrates how to handle Gestures in Qt. Qt provides a gesture framework that handles user panning, pinching, and swiping. It allows the user to extend the gesture recognizer and to interact and handle application gestures of there own. The framework uses the QGesture class.To indicate the widget about the incoming gestures, it must invoke grabGesture, passing the gesture ID of the gesture it can handle.
We will create an example that shows how to use the Pinch Gesture (and other gestures)
QWidget doesn’t define an explicit event handler for gestures, so we need to catch these gestures in QWidget’s event method:
The gestureEvent method is not an in-build method of QWidget class, we implemented this method to handle gestures recognition and actions.
Each of the individual gesture handlers called form gestureEvent do the actual gesture handling and then we perform the widget-specific processing, such as panning, rotating etc. For example in pinching the user may adjust the distance between the two touched points repeatedly to see the same content at different zoom levels. For more information on writing a gesture recognizer see Gestures Programming
The full source code presented in this article is available here File:GesturesQt.zip
- index.php/Enabling pinch zooming in QGraphicsWebView with QPinchGesture
- index.php/Custom Swipe Gestures in Qt
--16:24, 16 May 2011 (EEST)