我试图做一个警告消息框,几秒钟后自动消失。 我已经完成了以下代码:
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_()
它实际上很好,自动关闭部分。 我的问题是,当有人试图在几秒钟前通过点击窗口的x按钮手动关闭它时,消息框永远不会关闭。“等待时间”变为负数,消息框显示“4秒后自动关闭”,它永远不会关闭。在
你知道我该怎么避免吗? 问候
试试我的解决方案, 我已经根据您的需求创建了一个新类型的QMessageBox
相关问题 更多 >
编程相关推荐