from PySide.QtCore import QBasicTimer class MyWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.progressBar = QtWidgets.QProgressBar() self.setCentralWidget(self.progressBar) self.timer = QBasicTimer() self.timer.start(100, self) def timerEvent(self, event): if event.timerId() == self.timer.timerId(): self.progressBar.setValue(self.progressBar.value() + 1) super().timerEvent(event)
from PySide.QtCore import QBasicTimer, Qt class MyWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.timer = QBasicTimer() self.timer.start(50, self) def timerEvent(self, event): if event.timerId() == self.timer.timerId(): if QtWidgets.QApplication.keyboardModifiers() == Qt.ControlModifier: self.doSomething() super().timerEvent(event) def doSomething(self): # ...In this code, we create a QBasicTimer object that fires every 50ms (as specified by the first argument to the `start()` function) and has `self` as the second argument again, indicating that we want the `timerEvent()` function to be called when the timer fires. In the `timerEvent()` function, we check if the event that triggered the timer was the one associated with our timer by checking the timer ID, and if so, we check if the user is currently holding down the Ctrl key. If so, we call a function called `doSomething()`. This example is just one possible use case of QBasicTimer – it can be used for a wide range of purposes, and is a simple and convenient way to implement time-based actions in PySide applications. QBasicTimer is part of the QtCore package library in PySide.