本文共 1910 字,大约阅读时间需要 6 分钟。
if __name__ == "__main__": ui_style = UIStyle().get_style() app = QtWidgets.QApplication(sys.argv) # 创建QSplashScreen对象实例 splash = QtWidgets.QSplashScreen(QtGui.QPixmap("UserView/logo.png")) # 设置画面中的文字的字体 splash.setFont(QFont('Microsoft YaHei UI', 12)) # 显示画面 splash.show() # 显示信息 splash.showMessage("启动中... 0%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) time.sleep(1) splash.showMessage("正在加载样式表...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("正在加载样式表...40%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) time.sleep(1) splash.showMessage("正在加载数据库配置...60%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) time.sleep(1) splash.showMessage("正在测试数据库连接...80%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) conn = GetMysqlConnection().get_connection() if(conn!=0): conn.close() splash.showMessage("正在测试数据库连接...Success", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) else: splash.showMessage("正在测试数据库连接...faild", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) time.sleep(2) splash.showMessage("启动中...100%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) time.sleep(2) ui = MainWindow() ui.show() # 当主界面显示后销毁启动画面 splash.finish(ui) sys.exit(app.exec_())
# 实现这个函数 def closeEvent(self, QCloseEvent): # 使用QMessageBox提示 reply = QMessageBox.warning(self, "温馨提示", "即将退出, 确定?", QMessageBox.Yes|QMessageBox.No, QMessageBox.No) if(reply == QMessageBox.Yes): QCloseEvent.accept() if(reply==QMessageBox.No): QCloseEvent.ignore()
转载于:https://blog.51cto.com/xvjunjie/2147904