I am trying to do a warning message box that disappears automatically after few seconds. I have done this code:
def warning(self):
messagebox = QtGui.QMessageBox(self)
messagebox.setWindowTitle("wait")
messagebox.setText("wait (closing automatically in {0} secondes.)".format(3))
messagebox.setStandardButtons(messagebox.NoButton)
self.timer2 = QtCore.QTimer()
self.time_to_wait = 3
def close_messagebox(e):
e.accept()
self.timer2.stop()
self.time_to_wait = 3
def decompte():
messagebox.setText("wait (closing automatically in {0} secondes.)".format(self.time_to_wait))
if self.time_to_wait <= 0:
messagebox.closeEvent = close_messagebox
messagebox.close()
self.time_to_wait -= 1
self.connect(self.timer2,QtCore.SIGNAL("timeout()"),decompte)
self.timer2.start(1000)
messagebox.exec_()
It works actually fine, for the automatic closing part. My problem is that when someone try to close it manually before the few seconds, by clicking on the x button of the window, the message box never closes. the "time to wait" goes negative, the message box shows "closing automatically in -4 seconds" for example, and it will never close.
Any idea how I could avoid that ? Regards