Qt Sensors - SensorGesture QML Type example

This example demonstrates use of the SensorGesture QML type.

Overview

To write a QML application that will use the gesture plugin you need to to the following steps:

Import the QtSensors 5.x declarative plugin:

import QtSensors 5.0

Add the SensorGesture QML type into your qml file.

    SensorGesture {
        id: sensorGesture
        enabled: false
        onDetected:{
            if (gesture !== oldgesture)
                count = 0;
            valueText.text = gesture + " " + count;
            oldgesture = gesture;
            count++;
        }
        onEnabledChanged: {
            valueText.text = ""
        }
    }

Each SensorGesture QML type contains a property called gestures.

In this example an alias 'gestureid' for this property is used.

    property alias gestureid: sensorGesture.gestures

By using this alias property you define which gestures should be used:

        onSelectedGestureChanged: {
            gesture.enabled = false;
            gesture.gestureid = gestureList.selectedGesture;

A list of all available gestures can be created by calling the 'availableGestures' property:

        ListView {
            id: gestureList
            anchors.fill: gestureListRect
            anchors.margins: 5
            model: gesture.availableGestures
            focus: true
            currentIndex: -1
            delegate: gestureListDelegate
            clip: true
        }

Files:

See also Qt Sensors - ShakeIt QML Example and Qt Sensor Gestures.