Skip to content

PythonQt.Qt.QGestureRecognizer

QGestureRecognizer

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

Gesture recognizers are responsible for creating and managing QGesture objects and monitoring input events sent to QWidget and QGraphicsObject subclasses. QGestureRecognizer is the base class for implementing custom gestures.

Developers that only need to provide gesture recognition for standard gestures do not need to use this class directly. Instances will be created behind the scenes by the framework.

For an overview of gesture handling in Qt and information on using gestures in your applications, see the Gestures in Widgets and Graphics View document.

Recognizing Gestures

The process of recognizing gestures involves filtering input events sent to specific objects, and modifying the associated QGesture objects to include relevant information about the user's input.

Gestures are created when the framework calls create() to handle user input for a particular instance of a QWidget or QGraphicsObject subclass. A QGesture object is created for each widget or item that is configured to use gestures.

Once a QGesture has been created for a target object, the gesture recognizer will receive events for it in its recognize() handler function.

When a gesture is canceled, the reset() function is called, giving the recognizer the chance to update the appropriate properties in the corresponding QGesture object.

Supporting New Gestures

To add support for new gestures, you need to derive from QGestureRecognizer to create a custom recognizer class, construct an instance of this class, and register it with the application by calling QGestureRecognizer::registerRecognizer(). You can also subclass QGesture to create a custom gesture class, or rely on dynamic properties to express specific details of the gesture you want to handle.

Your custom QGestureRecognizer subclass needs to reimplement the recognize() function to handle and filter the incoming input events for QWidget and QGraphicsObject subclasses. Although the logic for gesture recognition is implemented in this function, you can store persistent information about the state of the recognition process in the QGesture object supplied. The recognize() function must return a value of QGestureRecognizer::Result that indicates the state of recognition for a given gesture and target object. This determines whether or not a gesture event will be delivered to a target object.

If you choose to represent a gesture by a custom QGesture subclass, you will need to reimplement the create() function to construct instances of your gesture class. Similarly, you may need to reimplement the reset() function if your custom gesture objects need to be specially handled when a gesture is canceled.

Source: https://doc.qt.io/archives/qt-5.15/qgesturerecognizer.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
CancelGesture attribute Any (shared captured text)
ConsumeEventHint attribute Any (shared captured text)
FinishGesture attribute Any (shared captured text)
Ignore attribute Any (shared captured text)
MayBeGesture attribute Any (shared captured text)
Result attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
ResultFlag attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
ResultHint_Mask attribute Any (shared captured text)
ResultState_Mask attribute Any (shared captured text)
TriggerGesture attribute Any (shared captured text)
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
create function (self, target: Any) -> Any X.create(target) -> PythonQt.QtGui.QGesture (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
recognize function (self, state: Any, watched: Any, event: Any) -> Any X.recognize(state, watched, event) (shared captured text)
registerRecognizer function (self, recognizer: Any) -> Any Registers the given recognizer in the gesture framework and returns a gesture ID for it. (shared captured text)
reset function (self, state: Any) -> None This function is called by the framework to reset a given gesture. (shared captured text)
unregisterRecognizer function (self, type: Any) -> None Unregisters all gesture recognizers of the specified type. (shared captured text)