Button press and hold example
-
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
-
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
@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.
-
@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()