Qt Sensors - SensorGesture QML Type example

概述

To write a QML application that will use the gesture plugin, following steps are needed:

Import the QtSensors 5.x module:


  import QtSensors 5.0
					

添加 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 = ""
          }
      }
					

每个 SensorGesture QML type contains a property called gestures. This example uses an alias gestureId for this property.


      property alias gestureId: sensorGesture.gestures
					

Then, the gesture or gestures to use can be specified using the alias:


          onSelectedGestureChanged: {
              gesture.enabled = false;
              gesture.gestureId = gestureList.selectedGesture;
              ...
          }
					

A list of all available gestures is accessible through the availableGestures 特性:


          ListView {
              id: gestureList
              model: gesture.availableGestures
              ...
          }
					

文件:

另请参阅 Qt Sensors - ShakeIt QML Example and Qt Sensor Gestures .