TouchScriptInterface Class

The TouchScriptInterface class enables you to create scripts that emulate touch gestures. More...

Header: #include <TouchScriptInterface>

Public Functions

void beginTouch(int id, int x, int y)
void endTouch(int id, int x, int y)
void setScreen(const QString &screenName)
void updateTouch(int id, int x, int y)

Detailed Description

The TouchScriptInterface class enables you to create scripts that emulate touch gestures.

Touch screens allow users to interact with devices by touching the screen with one or more fingers.You can create scripts that emulate touch gestures, such as tap, pinch, pan, and swipe.

In the scripts, you can either use screen cordinates to indicate touch points, or specify them as relative to the position of the mouse on the screen.

The TouchScriptInterface class is exposed as touch.

For example, the following example script emulates a pan event:

var startX = emulator.displayInfo()[0].width * 0.2;
var endX = emulator.displayInfo()[0].width - endX;
var y = emulator.displayInfo()[0].height / 2;
var x = startX;

// This is the name of the screen specified in the QML model file
touch.setScreen("screen1");

touch.beginTouch(0, x, y - 30);
touch.beginTouch(1, x, y + 30);

while (x < endX) {
    x += 10;
    touch.updateTouch(0, x, y - 30);
    touch.updateTouch(1, x, y + 30);
    yield(1);
}

touch.endTouch(0, x, y - 30);
touch.endTouch(1, x, y + 30);

First, the beginTouch() function is used to specify two touch points with the identifiers 0 and 1 that are relative to the position of the mouse on the screen. Second, the updateTouch() function is used to update the touch points to move the content on the screen. Finally, the endTouch() function is used to release the touch points and to end the pan event.

For more touch script examples, see scripts/examples/.

Member Function Documentation

void TouchScriptInterface::beginTouch(int id, int x, int y)

Begins the touch event by creating a touch point with the identifier id in the position specified by x and y.

void TouchScriptInterface::endTouch(int id, int x, int y)

Ends the touch event by releasing the touch point with the identifier id in the position specified by x and y.

void TouchScriptInterface::setScreen(const QString &screenName)

void TouchScriptInterface::updateTouch(int id, int x, int y)

Moves the touch point with the identifier id to the position specified by x and y.

© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.