Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Swipe Gesture with Qt Quick 2.0 and Qt 5.2
Forum Updated to NodeBB v4.3 + New Features

Swipe Gesture with Qt Quick 2.0 and Qt 5.2

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 6.1k Views 1 Watching
  • 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.
  • GianlucaG Offline
    GianlucaG Offline
    Gianluca
    wrote on last edited by
    #1

    Dear all,
    I can't find a way to recognize a swipe gesture using Qt Quick 2.2 and Qt 5.2 on a mobile devices (multi-touch screen).
    Searching on the forums, I saw various post about the Qt.labs GestureArea but that project is no anymore updated since threes years ago, and it has not been integrated into Qt 5.2
    So, what's the alternative ??
    Someone has a code to share with the community that recognize a swipe using Qt Quick 2 ??

    Thanks,
    Gianluca.

    1 Reply Last reply
    0
    • X Offline
      X Offline
      Xander84
      wrote on last edited by
      #2

      what about "MultiPointTouchArea":http://qt-project.org/doc/qt-5/qml-qtquick-multipointtoucharea.html?

      1 Reply Last reply
      0
      • GianlucaG Offline
        GianlucaG Offline
        Gianluca
        wrote on last edited by
        #3

        Honestly, I'm looking for something more that just what Item to use.
        I know that I have to use a MultiPointTouchArea or a MouseArea ... but how ??
        Someone has a bit of code to share ?? or some consideration about how to calculate the velocity of a touch movement ? what it should be a velocity threshold that tipically correspond to a swipe ? how far tipycally a swipe last ?? etc ..

        Thanks,
        Gianluca.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerMas
          wrote on last edited by
          #4

          @Gianluca

          Could you find a solution for implementing the swipe gesture?

          1 Reply Last reply
          0
          • GianlucaG Offline
            GianlucaG Offline
            Gianluca
            wrote on last edited by
            #5

            I get a solution that works in my case, but honestly I don't know how robust it is and how correct is the calculation.
            Here the code:
            @ MouseArea {
            id: globalMouseArea
            anchors.fill: parent
            preventStealing: true
            property real velocity: 0.0
            property int xStart: 0
            property int xPrev: 0
            property bool tracing: false
            onPressed: {
            xStart = mouse.x
            xPrev = mouse.x
            velocity = 0
            tracing = true
            }
            onPositionChanged: {
            if ( !tracing ) return
            var currVel = (mouse.x-xPrev)
            velocity = (velocity + currVel)/2.0
            xPrev = mouse.x
            if ( velocity > 15 && mouse.x > parent.width0.2 ) {
            tracing = false
            // SWIPE DETECTED !! EMIT SIGNAL or DO your action
            }
            }
            onReleased: {
            tracing = false
            if ( velocity > 15 && mouse.x > parent.width
            0.2 ) {
            // SWIPE DETECTED !! EMIT SIGNAL or DO your action
            }
            }
            }
            @

            The code above detect only the swipe from left to right !!
            For detecting swipe from right to left you should change the checks into the if
            @
            if ( velocity < 15 && mouse.x < parent.width*0.2 )
            @
            And for detecting top-down swipe you should change again the if checking the movement on the Y coordinates

            I made various assumption about the swipe gesture that I don't know if they are correct:

            the frame rate of UI updates are constant, so the velocity can be expressed as the pixel changes from one frame to another

            the velocity of the swipe has to be greater that 15 pixel/frame_update

            the minimum length of a swipe is the 20% of the width of the screen

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DerMas
              wrote on last edited by
              #6

              Thanks for your reply, going to try it :)

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved