P
By specifying True to the setAutoRepeat method of the QクラスButton class (superclass of the QPushButton class), pressed, released, and clicked signals will occur at a fixed interval. https://doc.qt.io/qt-5/qabstractbutton.html#autoRepeat-prop Specifies the interval of the signal to be generated by the autoRepeatInterval method until the setAutoRepeatDelay method is determined to be pushed out. Both arguments are specified in milliseconds.Example code.import sys
from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
self.counter = 0
def initUI(self):
btn2 = QPushButton("Button", self)
btn2.move(50, 50)
btn2.setAutoRepeat(True)
btn2.setAutoRepeatDelay(1000) # 1秒
btn2.setAutoRepeatInterval(300) # 300ミリ秒
btn2.pressed.connect(self.updateStatusBar)
self.statusBar()
self.setGeometry(300, 300, 200, 150)
self.show()
def updateStatusBar(self):
self.counter += 1
msg = self.sender().text() + ' was pressed... {}'.format(self.counter)
self.statusBar().showMessage(msg)
if name == 'main':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
If you press the Button that appears on the screen for more than one second, you can check that the value at the end of the status bar is incremented every 300 millisecond.