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. Timer running on mouseArea.pressed
QtWS25 Last Chance

Timer running on mouseArea.pressed

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 917 Views
  • 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.
  • ealioneE Offline
    ealioneE Offline
    ealione
    wrote on last edited by
    #1

    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
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      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
      0
      • ealioneE Offline
        ealioneE Offline
        ealione
        wrote on last edited by
        #3

        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
        0
        • ealioneE Offline
          ealioneE Offline
          ealione
          wrote on last edited by
          #4

          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
          0

          • Login

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