개발/Qt
[Qt] 메시지 박스(QMessageBox) 몇 초 후 자동으로 사라지게 하기
LifeCoding
2021. 11. 16. 17:28
3초 후 자동으로 사라지는 메시지 박스 띄우기
timer를 만들어서, timeout시 메시지 박스 close 함수를 호출하게 하면 된다.
C++ 코드 :
QMessageBox msgBox(QMessageBox::Information, tr("title"), tr("message..."), QMessageBox::Ok, this);
QTimer timer;
timer.singleShot(3000, &msgBox, &QMessageBox::close);
msgBox.exec();
Python 코드:
from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtCore import Qt, QTimer
def showMessage():
msg = QMessageBox(QMessageBox.Information, "title", "text", QMessageBox.Ok, None, Qt.WindowStaysOnTopHint)
timer = QTimer()
timer.singleShot(3000, msg.close)
msg.exec()
import sys
def start():
app = QApplication(sys.argv)
showMessage()
sys.exit(app.exec_())
if __name__ == '__main__':
start()