Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Timer running on mouseArea.pressed

    QML and Qt Quick
    2
    4
    699
    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.
    • ealione
      ealione last edited by

      I had the idea of making a button that only if held for some time it would unlock its functionality. If pressed and released immediately nothing would happen.

      I am at the point where I created my button (a cute circular one) that when pressed animates to a scale 1.2 times bigger its original size and the text changes from 'Press and Hold' to 'Hold'.

      I also placed an arc around this button, that will act as a circular loader and will reach 100% at the time the button is finally ready to be released.

      What I am not sure how is done though is having a function with a timer that kicks in as long as the button is pressed and after the required time (lets say 2s) has passed will emit a signal or do whatever else the button is supposed to do.

      Any tips would be welcomed.

      1 Reply Last reply Reply Quote 0
      • M
        mcosta last edited by

        Hi,

        soon (in Qt 5.5) you'll have this.

        BTW, you should have a timer that

        • is started when the button is pressed
        • is stopped when the button is released
        • expires after the interval

        so you can catch the timeout signal and execute your function

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        1 Reply Last reply Reply Quote 0
        • ealione
          ealione last edited by

          Hi mcosta, weird thats exactly what I am making. I had no idea it would be included in 5.5

          The thing is that not only I want my timer to expire after the lets say 2 seconds, but I also want it to update my circular loader in the meantime. And I don't know how to do that.

          1 Reply Last reply Reply Quote 0
          • ealione
            ealione last edited by

            I moved a little bit using the following

            Timer {
                    id: elapsedTimer
                    interval: 10; running: false; repeat: false
                    onTriggered: canvas.timeChanged()
                }
            
            function timeChanged() {
                    canvas.currentValue = canvas.currentValue + 1
                    if(canvas.currentValue >= 100) {
                        // here I must emit a signal
                    }
                }
            

            Now I will enter inside the if condition at the desired time. But what should I do once I am in there?
            Can I somehow emit a signal so whoever is using the button can attach to it?

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