[sovled][Windows Phone 8.1][5.4] QML MouseArea pressAndHold signal not working properly.



  • Hey,

    I got a problem with pressAndHold signal in mouseArea. The problem is that signal is emitted right after clicking on the area instead after some time(800ms according to documentation http://doc.qt.digia.com/qt-5.2/qml-qtquick-mousearea.html#onPressAndHold-signal).

    So got a question, is there a way to manually set the long press time? I think this could fix it.


  • Lifetime Qt Champion

    Hi,

    AFAIK no, it's a constant that cannot be currently changed



  • Hi,

    I also experienced that issue, this seems to be a bug in the Win RT port.

    As a workaround you can add your own timer and kind of simulate the pressAndHold behavior like the following code snippet (this snippet also handles the clicked signal, you can strip some code if you don't need that):

    @MouseArea {
    id: innerArea

    // Internal properties for pressAndHold handling
    property bool __isLongPress: false
    property real __initialY: 0
    
    onClicked: {
      // Don't handle clicked signal if it is a long press
      if (__isLongPress)
        return
    
      // Handle the clicked signal here
    }
    
    onPressed: {
      if (!pressAndHoldTimer.running) {
        __isLongPress = false
        pressAndHoldTimer.restart()
        __initialY = mouseY
      }
    }
    
    onReleased: {
      if (pressAndHoldTimer.running) {
        pressAndHoldTimer.stop()
      }
    }
    
    onPositionChanged: {
      // Check for some absolute movement before canceling timer
      if (pressAndHoldTimer.running && Math.abs(mouseY - __initialY) > 10) {
        pressAndHoldTimer.stop()
      }
    }
    
    Timer {
      id: pressAndHoldTimer
    
      interval: 800
    
      onTriggered: {
        innerArea.__isLongPress = true
        
        // Handle the pressAndHold signal here
      }
    }
    

    }@

    You can also up-vote the bug report here to get it fixed faster: https://bugreports.qt.io/browse/QTBUG-44606

    Cheers,
    Alex from V-Play



  • Thanks for help, had same idea as you, but I wasnt sure if its a bug or my mistake.

    Anyway I think it's solved since there is simple workaround. But still I up-voted the bug.



  • The bug has been fixed a few weeks ago in the Qt 5.4.1 version.


Log in to reply
 

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