maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   SailfishOS (https://talk.maemo.org/forumdisplay.php?f=52)
-   -   Decrease onPressAndHold duration (https://talk.maemo.org/showthread.php?t=100398)

Markkyboy 2018-07-20 08:04

Decrease onPressAndHold duration
 
Hi all,

as per the title of this post, I'm wanting to decrease the duration of 'onPressAndHold', I've found a few suggestions on StackExchange but have not been able to make it work for my case.

Rather than posting any and all attempts I've made, I'd like to make it work with what little I have originally coded so far, but the duration is a tad too long; how do I reduce the duration?......

Code:

    MouseArea {
          anchors.fill: root
          propagateComposedEvents: true
          onPressAndHold: view.closeTab(index)
    }
}

I understand that perhaps a 'Timer' needs to be used, but I just cannot fathom how to do it, any ideas gratefully received!

coderus 2018-07-20 09:25

Re: Decrease onPressAndHold duration
 
onPressed: timer.start()
onReleased: timer.stop()
onCancel: timer.stop()
timer.onTriggered: view.closeTab(index)

Markkyboy 2018-07-20 14:20

Re: Decrease onPressAndHold duration
 
Quote:

Originally Posted by coderus (Post 1546369)
onPressed: timer.start()
onReleased: timer.stop()
onCancel: timer.stop()
timer.onTriggered: view.closeTab(index)

Perfect!, I was fairly close with one of my attempts, but you have succeeded where I failed (again) and all with less code than I had applied.

Eventually........

Code:

        MouseArea {
            anchors.fill: root
            propagateComposedEvents: true
            onPressed: {
                timer.start();
            }
            onReleased: {
                timer.stop();
            }
            Timer {
                id: timer
                interval: 500
                onTriggered: {
                    view.closeTab(index)
                }
            }
        }

......this will evolve :)

Thanks again, coderus

Regards,

coderus 2018-07-20 16:51

Re: Decrease onPressAndHold duration
 
add timer stop to onCanceled and onExited


All times are GMT. The time now is 22:55.

vBulletin® Version 3.8.8