Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 the framework 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 18 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 21 of file qgesturerecognizer.h.

Constructor & Destructor Documentation

◆ QGestureRecognizer()

QGestureRecognizer::QGestureRecognizer ( )

Constructs a new gesture recognizer object.

Definition at line 116 of file qgesturerecognizer.cpp.

◆ ~QGestureRecognizer()

QGestureRecognizer::~QGestureRecognizer ( )
virtual

Destroys the gesture recognizer.

Definition at line 123 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.

The application takes ownership of the created gesture object.

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

Definition at line 136 of file qgesturerecognizer.cpp.

References Q_UNUSED.

Referenced by QGestureManager::registerGestureRecognizer().

+ Here is the caller graph for this function:

◆ recognize()

QGestureRecognizer::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 QMacSwipeGestureRecognizer, QMacPinchGestureRecognizer, QMacPanGestureRecognizer, QPanGestureRecognizer, QPinchGestureRecognizer, QSwipeGestureRecognizer, QTapGestureRecognizer, QTapAndHoldGestureRecognizer, and QFlickGestureRecognizer.

Referenced by QGestureManager::filterEventThroughContexts().

+ Here is the caller graph for this function:

◆ registerRecognizer()

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

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

The application takes ownership of the recognizer and returns the gesture type ID associated with it. For gesture recognizers which handle custom QGesture objects (i.e., those which 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 187 of file qgesturerecognizer.cpp.

References QGestureManager::instance().

Referenced by QScroller::grabGesture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

void QGestureRecognizer::reset ( QGesture * gesture)
virtual

This function is called by the framework 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 QMacSwipeGestureRecognizer, QMacPinchGestureRecognizer, QMacPanGestureRecognizer, QPanGestureRecognizer, QPinchGestureRecognizer, QSwipeGestureRecognizer, QTapGestureRecognizer, QTapAndHoldGestureRecognizer, and QFlickGestureRecognizer.

Definition at line 149 of file qgesturerecognizer.cpp.

References d, Qt::NoGesture, and QGesture::state.

Referenced by QGestureManager::recycle(), QMacSwipeGestureRecognizer::reset(), QMacPinchGestureRecognizer::reset(), QMacPanGestureRecognizer::reset(), QPanGestureRecognizer::reset(), QPinchGestureRecognizer::reset(), QSwipeGestureRecognizer::reset(), QTapGestureRecognizer::reset(), QTapAndHoldGestureRecognizer::reset(), and QFlickGestureRecognizer::reset().

+ Here is the caller graph for this function:

◆ unregisterRecognizer()

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

Unregisters all gesture recognizers of the specified type.

See also
registerRecognizer()

Definition at line 197 of file qgesturerecognizer.cpp.

References QApplicationPrivate::instance(), and QGestureManager::instance().

Referenced by QScroller::~QScroller(), and QScroller::ungrabGesture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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