Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Push button long&short time press control
Forum Updated to NodeBB v4.3 + New Features

Push button long&short time press control

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 5.0k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    rapid84
    wrote on last edited by rapid84
    #1

    Hi,
    I want to control a pushbutton long or short time pressed status with a timer. If i use with "::on_pushButton_pressed()" and "::on_pushButton_released()" how can i check the pressed time ? Or which way must i use ?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You want to know how long a user hold down the button?
      There is
      http://doc.qt.io/qt-5.5/qelapsedtimer.html#details

      1 Reply Last reply
      1
      • R Offline
        R Offline
        rapid84
        wrote on last edited by
        #3

        @mrjj
        Yes, i want to know if button pressed short and released or it is pressed long time (maybe 1000ms). first i think maybe a timer can be defined globally and button pressed and released functions can be used to control the short or long press, but i can not use a global timer , you maybe give idea more clearly.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Ok, it doesn't have to be global, but could live
          in the class that has ::on_pushButton_XX

          Alternatively you could subclass QPushButton and create one
          that can do this it self ? (internal handling of the QElapsedTimer)

          Can I ask why you need to know this?
          Most will just click it and released will come very fast.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rapid84
            wrote on last edited by rapid84
            #5

            @mrjj
            Because my button must do 2 different work according to the short or long press. if it is pressed short, it execute a mission and if it is pressed long it executes another different work.

            mrjjM 1 Reply Last reply
            0
            • R rapid84

              @mrjj
              Because my button must do 2 different work according to the short or long press. if it is pressed short, it execute a mission and if it is pressed long it executes another different work.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @rapid84
              ok. I understand.
              There is also
              http://doc.qt.io/qt-5.5/qabstractbutton.html#autoRepeat-prop
              You could just "count" and use the count to decide if function 1 or 2.

              If you need this for more that 1 button, a new Button type is the way to go.
              You could even make new signal giving the pressed time or count.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                rapid84
                wrote on last edited by
                #7

                @mrjj
                As far as i understand autoRepeat() make buttons do same thing periodically,( am i right ? ) . But i want my button do something "only once" as far as it is pressed long until it is released .

                mrjjM 1 Reply Last reply
                0
                • R rapid84

                  @mrjj
                  As far as i understand autoRepeat() make buttons do same thing periodically,( am i right ? ) . But i want my button do something "only once" as far as it is pressed long until it is released .

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @rapid84
                  yes, it often used for that. But you could also use it to keep track of
                  how long it was pressed.
                  Since it will also give mutiple released , i guess using
                  QElapsedTimer is easier.

                  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