Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Button press and hold example
Forum Updated to NodeBB v4.3 + New Features

Button press and hold example

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 992 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.
  • C Offline
    C Offline
    Captain Haddock
    wrote on last edited by
    #1

    I want to create a label on a dialog whose numeric text value increments while a button on the same dialog is kept pressed down, e.g. each 1 second the left mouse button is still held down the value increments by 1.

    Does anyone have sample code for something similar?

    Thanks

    jsulmJ 1 Reply Last reply
    0
    • C Captain Haddock

      I want to create a label on a dialog whose numeric text value increments while a button on the same dialog is kept pressed down, e.g. each 1 second the left mouse button is still held down the value increments by 1.

      Does anyone have sample code for something similar?

      Thanks

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Captain-Haddock I don't have sample code. But you can simply use QTimer and start it as soon as the button is pressed down and stop it as soon as the button is released. Set the QTimer timeout to 1000 (1sec) and increment the number on each timeout.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • C Offline
        C Offline
        Captain Haddock
        wrote on last edited by Captain Haddock
        #3

        @jsulm doh! .. thanks, of course .. based on QTimer this works:

            monthPlusButton.pressed.connect(lambda: self.mousePressed("m+"))
            monthPlusButton.released.connect(self.mouseReleased)
        
        def mousePressed(self, action):
            self.scrollTimer = QtCore.QTimer()
            match action:
                case "m+":
                    self.scrollTimer.timeout.connect(self.incrementMonth)
            self.scrollTimer.start(500)
        
        def mouseReleased(self):
            self.scrollTimer.stop()
        
        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