Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

PyQt5 development notes, how to achieve the program startup screen and exit prompt?

Shulou Source: shulou.com Published: 2022-06-03 07:54:25 09月23日 Update

Program launch screen: if _ _ name__ = "_ _ main__": ui_style = UIStyle (). Get_style () app = QtWidgets.QApplication (sys.argv) # create QSplashScreen object instance splash = QtWidgets.QSplashScreen ("UserView/logo.png") # set the font splash.setFont of the text in the screen (QFont ('Microsoft YaHei UI') 12) # display screen splash.show () # display information splash.showMessage ("starting. 0%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) time.sleep (1) splash.showMessage ("loading style sheet .20%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom QtCore.Qt.white) if (ui_style=='dark'): app.setStyleSheet (qdarkstyle.load_stylesheet_pyqt5 ()) time.sleep (1) splash.showMessage ("loading stylesheet .40%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) time.sleep (1) splash.showMessage ("loading database configuration .60%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom QtCore.Qt.white) time.sleep (1) splash.showMessage ("testing database connection. 80%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) conn = GetMysqlConnection (). Get_connection () if (connexion 0): conn.close () splash.showMessage ("testing database connection. Success", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom QtCore.Qt.white) else: splash.showMessage ("testing database connection. Faild", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) time.sleep (2) splash.showMessage ("starting .100%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom QtCore.Qt.white) time.sleep (2) ui = MainWindow () ui.show () # destroy the splash screen splash.finish (ui) sys.exit (app.exec_ ()) when the main interface is displayed

Program exit prompt # implement this function def closeEvent (self, QCloseEvent): # use QMessageBox prompt reply = QMessageBox.warning (self, "warm prompt", "exit soon, are you sure?" , QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if (reply== QMessageBox.Yes): QCloseEvent.accept () if (reply==QMessageBox.No): QCloseEvent.ignore ()

Tags: Screen data database prompt test program style warmth information function font instance object text interface configuration memo development Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Technology Microsoft MySQL vpn