April 7, 2011

qtnext qtnext
Lab Rat
149 posts

PinchArea

 

I am trying to use PinchArea (Qt Quick 1.1) : I have the following :

  1. import QtQuick 1.1
  2.  
  3. Rectangle {
  4.     width: 300
  5.     height: 200
  6.     color:"blue"
  7.     id :mainMT
  8.  
  9.  
  10.     PinchArea {
  11.         property int xpoint
  12.         property int ypoint
  13.         property int pinchscale
  14.         property int pinchrotation
  15.  
  16.  
  17.         id: pinchy
  18.         enabled: true
  19.         anchors.fill: parent
  20.         pinch.dragAxis: Pinch.XandYAxis
  21.         pinch.minimumScale: 0.01
  22.         pinch.maximumScale: 20
  23.         onPinchUpdated:
  24.         {
  25.             mainMT.x+=-mapToItem(mainMT.parent,pinch.previousCenter.x,pinch.previousCenter.y).x+mapToItem(mainMT.parent,pinch.center.x,pinch.center.y).x;
  26.             mainMT.y+=-mapToItem(mainMT.parent,pinch.previousCenter.x,pinch.previousCenter.y).y+mapToItem(mainMT.parent,pinch.center.x,pinch.center.y).y;
  27.             mainMT.scale-=pinch.previousScale-pinch.scale;
  28.             mainMT.rotation+=pinch.previousAngle-pinch.angle;
  29.          }
  30.     }
  31. }

It works well except than it’s difficult to move the item with two fingers : when you do that, there is rotation that comes with …
Is there a way to enable single touch to move item instead of double touch to distinct move object, and scale/rotation ?

1 reply

April 8, 2011

mbrasser mbrasser
Lab Rat
452 posts

A couple things you could try:

  • filtering the data in onPinchUpdated (e.g. only change the rotation when the difference in angle passes a certain threshold)
  • use a MouseArea for the single finger dragging (from memory MouseArea and PinchArea should work well together)

 
  ‹‹ QAbstractListModel return a QObject and use it in qml?      [SOLVED] Getting anchors from C++ ››

You must log in to post a reply. Not a member yet? Register here!