PinchHandler QML Type

Handler for pinch gestures. More...

Import Statement: import Qt.labs.handlers 1.0
Inherits:

MultiPointHandler

Properties

Detailed Description

PinchHandler is a handler that interprets a multi-finger gesture to interactively rotate, zoom, and drag an Item. Like other Pointer Handlers, by default it is fully functional, and manipulates its target, which is the Item within which it is declared.

import QtQuick 2.8
import Qt.labs.handlers 1.0

Rectangle {
    width: 400
    height: 300
    color: "lightsteelblue"
    PinchHandler { }
}

It has properties to restrict the range of dragging, rotation, and zoom.

If it is declared within one Item but is assigned a different target, it handles events within the bounds of the outer Item but manipulates the target Item instead:

import QtQuick 2.8
import Qt.labs.handlers 1.0

Item {
    width: 640
    height: 480

    Rectangle {
        id: map
        color: "aqua"
        width: 400
        height: 300
    }

    PinchHandler {
        target: map
    }
}

A third way to use it is to set target to null and react to property changes in some other way:

import QtQuick 2.8
import Qt.labs.handlers 1.0

Item {
    width: 640
    height: 480

    PinchHandler {
        id: handler
        target: null
    }

    Text {
        color: handler.active ? "darkgreen" : "black"
        text: handler.rotation.toFixed(1) + " degrees\n" +
              handler.translation.x.toFixed(1) + ", " + handler.translation.y.toFixed(1) + "\n" +
              (handler.scale * 100).toFixed(1) + "%"
    }
}

See also PinchArea.

Property Documentation

active : bool

This property is true when all the constraints (epecially minimumTouchPoints) are satisfied and the target, if any, is being manipulated.


[read-only] centroid : QPointF

A point exactly in the middle of the currently-pressed touch points. If pinchOrigin is set to PinchCenter, the target will be rotated around this point.


[read-only] centroidVelocity : QVector2D

The average velocity of the centroid: a vector representing the speed and direction of movement of the whole group of touchpoints, in logical pixels per second.


maximumRotation : real

The maximum acceptable rotation to be applied to the target.


maximumScale : real

The maximum acceptable scale to be applied to the target.


maximumX : real

The maximum acceptable x coordinate of the centroid


maximumY : real

The maximum acceptable y coordinate of the centroid


minimumRotation : real

The minimum acceptable rotation to be applied to the target.


minimumScale : real

The minimum acceptable scale to be applied to the target.


minimumTouchPoints : int

The pinch begins when this number of fingers are pressed. Until then, PinchHandler tracks the positions of any pressed fingers, but if it's an insufficient number, it does not scale or rotate its target, and the active property will remain false.


minimumX : real

The minimum acceptable x coordinate of the centroid


minimumY : real

The minimum acceptable y coordinate of the centroid


pinchOrigin : real

The point to be held in place, around which the target is scaled and rotated.

ConstantDescription
FirstPointthe first touch point, wherever the first finger is pressed
PinchCenterthe centroid between all the touch points at the time when the PinchHandler becomes active
TargetCenterthe center of the target

[read-only] rotation : real

The rotation of the pinch gesture in degrees, with positive values clockwise. It is 0 when the gesture begins. If target is not null, this will be automatically applied to its rotation. Otherwise, bindings can be used to do arbitrary things with this value.


[read-only] scale : real

The scale factor. It is 1.0 when the gesture begins, increases as the touchpoints are spread apart, and decreases as the touchpoints are brought together. If target is not null, this will be automatically applied to its scale. Otherwise, bindings can be used to do arbitrary things with this value.


[read-only] translation : QVector2D

The translation of the gesture centroid. It is (0, 0) when the gesture begins.


© 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.