Swipe Gesture with Qt Quick 2.0 and Qt 5.2



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





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



  • @Gianluca

    Could you find a solution for implementing the swipe gesture?



  • 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



  • Thanks for your reply, going to try it :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.