Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QGestureRecognizer Class Referenceabstract

The QGestureRecognizer class provides the infrastructure for gesture recognition.\inmodule QtWidgets. More...

#include <qgesturerecognizer.h>

Inheritance diagram for QGestureRecognizer:
Collaboration diagram for QGestureRecognizer:

Public Types

enum  ResultFlag {
  Ignore = 0x0001 , MayBeGesture = 0x0002 , TriggerGesture = 0x0004 , FinishGesture = 0x0008 ,
  CancelGesture = 0x0010 , ResultState_Mask = 0x00ff , ConsumeEventHint = 0x0100 , ResultHint_Mask = 0xff00
}
 This enum describes the result of the current event filtering step in a gesture recognizer state machine. More...

Public Member Functions

 QGestureRecognizer ()
 Constructs a new gesture recognizer object.
virtual ~QGestureRecognizer ()
 Destroys the gesture recognizer.
virtual QGesturecreate (QObject *target)
 This function is called by Qt to create a new QGesture object for the given target (QWidget or QGraphicsObject).
virtual Result recognize (QGesture *state, QObject *watched, QEvent *event)=0
 Handles the given event for the watched object, updating the state of the gesture object as required, and returns a suitable result for the current recognition step.
virtual void reset (QGesture *state)
 This function is called by Qt to reset a given gesture.

Static Public Member Functions

static Qt::GestureType registerRecognizer (QGestureRecognizer *recognizer)
 Registers the given recognizer in the gesture framework and returns a gesture ID for it.
static void unregisterRecognizer (Qt::GestureType type)
 Unregisters all gesture recognizers of the specified type.

Detailed Description

The QGestureRecognizer class provides the infrastructure for gesture recognition.

\inmodule QtWidgets.

Since
4.6

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 \l{Gestures in Widgets and Graphics View} document.

Definition at line 19 of file qgesturerecognizer.h.

Member Enumeration Documentation

◆ ResultFlag

This enum describes the result of the current event filtering step in a gesture recognizer state machine.

The result consists of a state value (one of Ignore, MayBeGesture, TriggerGesture, FinishGesture, CancelGesture) and an optional hint (ConsumeEventHint).

\value Ignore The event does not change the state of the recognizer.

\value MayBeGesture The event changed the internal state of the recognizer, but it isn't clear yet if it is a gesture or not. The recognizer needs to filter more events to decide. Gesture recognizers in the MayBeGesture state may be reset automatically if they take too long to recognize gestures.

\value TriggerGesture The gesture has been triggered and the appropriate QGesture object will be delivered to the target as a part of a QGestureEvent.

\value FinishGesture The gesture has been finished successfully and the appropriate QGesture object will be delivered to the target as a part of a QGestureEvent.

\value CancelGesture The event made it clear that it is not a gesture. If the gesture recognizer was in GestureTriggered state before, then the gesture is canceled and the appropriate QGesture object will be delivered to the target as a part of a QGestureEvent.

\value ConsumeEventHint This hint specifies that the gesture framework should consume the filtered event and not deliver it to the receiver.

\omitvalue ResultState_Mask \omitvalue ResultHint_Mask

See also
QGestureRecognizer::recognize()
Enumerator
Ignore 
MayBeGesture 
TriggerGesture 
FinishGesture 
CancelGesture 
ResultState_Mask 
ConsumeEventHint 
ResultHint_Mask 

Definition at line 22 of file qgesturerecognizer.h.

Constructor & Destructor Documentation

◆ QGestureRecognizer()

QGestureRecognizer::QGestureRecognizer ( )

Constructs a new gesture recognizer object.

Definition at line 117 of file qgesturerecognizer.cpp.

◆ ~QGestureRecognizer()

QGestureRecognizer::~QGestureRecognizer ( )
virtual

Destroys the gesture recognizer.

Definition at line 124 of file qgesturerecognizer.cpp.

Member Function Documentation

◆ create()

QGesture * QGestureRecognizer::create ( QObject * target)
virtual

This function is called by Qt to create a new QGesture object for the given target (QWidget or QGraphicsObject).

Reimplement this function to create a custom QGesture-derived gesture object if necessary.

QApplication takes ownership of the created gesture object.

Reimplemented in QFlickGestureRecognizer, QMacPanGestureRecognizer, QMacPinchGestureRecognizer, QMacSwipeGestureRecognizer, QPanGestureRecognizer, QPinchGestureRecognizer, QSwipeGestureRecognizer, QTapAndHoldGestureRecognizer, and QTapGestureRecognizer.

Definition at line 137 of file qgesturerecognizer.cpp.

◆ recognize()

virtual Result QGestureRecognizer::recognize ( QGesture * gesture,
QObject * watched,
QEvent * event )
pure virtual

Handles the given event for the watched object, updating the state of the gesture object as required, and returns a suitable result for the current recognition step.

This function is called by the framework to allow the recognizer to filter input events dispatched to QWidget or QGraphicsObject instances that it is monitoring.

The result reflects how much of the gesture has been recognized. The state of the gesture object is set depending on the result.

See also
QGestureRecognizer::Result

Implemented in QFlickGestureRecognizer, QMacPanGestureRecognizer, QMacPinchGestureRecognizer, QMacSwipeGestureRecognizer, QPanGestureRecognizer, QPinchGestureRecognizer, QSwipeGestureRecognizer, QTapAndHoldGestureRecognizer, and QTapGestureRecognizer.

◆ registerRecognizer()

Qt::GestureType QGestureRecognizer::registerRecognizer ( QGestureRecognizer * recognizer)
static

Registers the given recognizer in the gesture framework and returns a gesture ID for it.

QApplication takes ownership of the recognizer, and this function returns the gesture type ID associated with it. For gesture recognizers that handle custom QGesture objects (those that return Qt::CustomGesture in a QGesture::gestureType() function), the return value is a generated gesture ID with the Qt::CustomGesture flag set.

See also
unregisterRecognizer(), QGestureRecognizer::create(), QGesture

Definition at line 188 of file qgesturerecognizer.cpp.

◆ reset()

void QGestureRecognizer::reset ( QGesture * gesture)
virtual

This function is called by Qt to reset a given gesture.

Reimplement this function to implement additional requirements for custom QGesture objects. This may be necessary if you implement a custom QGesture whose properties need special handling when the gesture is reset.

Reimplemented in QFlickGestureRecognizer, QMacPanGestureRecognizer, QMacPinchGestureRecognizer, QMacSwipeGestureRecognizer, QPanGestureRecognizer, QPinchGestureRecognizer, QSwipeGestureRecognizer, QTapAndHoldGestureRecognizer, and QTapGestureRecognizer.

Definition at line 150 of file qgesturerecognizer.cpp.

◆ unregisterRecognizer()

void QGestureRecognizer::unregisterRecognizer ( Qt::GestureType type)
static

Unregisters all gesture recognizers of the specified type.

See also
registerRecognizer()

Definition at line 198 of file qgesturerecognizer.cpp.


The documentation for this class was generated from the following files: