May 2019
Intermediate to advanced
542 pages
13h 37m
English
QTimer has a few methods that we can use to extract information about the state of the timer. For example, let's keep our user updated on how things are going with the following lines of code:
self.timer2 = qtc.QTimer() self.timer2.setInterval(1000) self.timer2.timeout.connect(self.update_status) self.timer2.start()
We've set up yet another timer that will call self.update_status() once every second. update_status() will then query the first time for information, as follows:
def update_status(self): if self.timer.isActive(): time_left = (self.timer.remainingTime() // 1000) + 1 self.statusBar().showMessage( f"Next dialog will be shown in {time_left} seconds.") else: self.statusBar().showMessage('Dialogs are ...Read now
Unlock full access