Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    MultiPointTouchArea onTouchUpdated remove all touchPoints

    QML and Qt Quick
    1
    2
    1077
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      NULL.Player last edited by NULL.Player

      Hello!
      First sorry for my english,
      I want to use MultiPointTouchArea, but it work works is not, as I think. For my trouble, I write a test code, like that(sorry, I don't understand the code layout in there):

      import QtQuick 2.0
      
      Rectangle {
          id: main
          color: "#11262B"
          width: 800
          height: 600
      
          // Visual presentation of the touch points
          Repeater {
              id: touchBalls
              model: multiArea.points
      
              Item {
                  x: modelData.x
                  y: modelData.y
      
                  Rectangle {
                      anchors.centerIn: parent
                      color: "white"
                      opacity: 0.1
                      width: 1000 * modelData.pressure
                      height: width
                      radius: width / 2
                  }
      
                  Rectangle {
                      anchors.centerIn: parent
                      color: "#20cc2c"
                      opacity: modelData.pressure * 10
                      width: 100
                      height: width
                      radius: width / 2
                  }
              }
          }
      
          // Text presentation of the touch points
          Column {
              spacing: 10
      
              Repeater {
                  model: multiArea.points
                  Text {
                      font.pointSize: 12
                      color: "snow"
                      text: "{ id: " + modelData.pointId + " x: " + modelData.x + ", y: " + modelData.y +
                            ", pressure: " + modelData.pressure + " }"
                  }
              }
          }
      
          // http://doc.qt.nokia.com/qt5/qml-qtquick2-multipointtoucharea.html
          MultiPointTouchArea {
              id: multiArea;
      
              property variant points: []
      
              function printTouchPoints(tps) {
                  for (var i = 0; i < tps.length; ++ i) {
                      console.log("id:", tps[i].pointId, ", (x, y): (", tps[i].x, tps[i].y, ")");
                  }
              }
      
              anchors.fill: parent;
      
              minimumTouchPoints: 1;
              maximumTouchPoints: 5;
      
              // Each of the event handlers have "touchPoints" available
              // http://doc.qt.nokia.com/qt5/qml-qtquick2-touchpoint.html
              onGestureStarted: {
                  console.log("multiArea onGestureStarted.", "getsture:", gesture.objectName);
              }
              onUpdated: {
                  console.log("multiArea onUpdated.", "touchPoints:", touchPoints.length, points.length);
                  points = touchPoints;
                  printTouchPoints(touchPoints);
              }
              onTouchUpdated: {
                  console.log("multiArea onTouchUpdated.", "touchPoints:", touchPoints.length, points.length);
                  points = touchPoints;
                  printTouchPoints(touchPoints);
              }
              onPressed: {
                  console.log("multiArea onPressed.", "touchPoints:", touchPoints.length, points.length);
                  points = touchPoints;
                  printTouchPoints(touchPoints);
              }
              onReleased: {
                  console.log("multiArea onReleased.", "touchPoints:", touchPoints.length, points.length);
                  points = touchPoints;
                  printTouchPoints(touchPoints);
              }
              onCanceled: {
                  console.log("multiArea onCanceled.", "touchPoints:", touchPoints.length, points.length);
                  points = touchPoints;
                  printTouchPoints(touchPoints);
              }
          }
      }
      

      the problem appear after the steps:

      1. touch the mobile screen use your one finger
      2. touch the mobile screen use your second finger
      3. remove the second finger from mobile screen

      now, the console and the mobile print told you the touchPoints.length is 0,
      but my first finger put still on screen.
      So, how it work normal, thank you in advance.

      Edited: Use ``` (3 backticks) - p3c0

      1 Reply Last reply Reply Quote 0
      • N
        NULL.Player last edited by

        Now I know some reason, that code work normal in QQuickView, bu I need QQuickWidget. When I remove second finger in QQuickWidget, MultiPointTouchArea will correspond handing is onCanceled, the Qt document tell me, "This signal is emitted when new touch events have been canceled because another item stole the touch event handling",
        Now, should I how to avoid "stole the touch"?

        1 Reply Last reply Reply Quote 0
        • First post
          Last post