diff --git a/QSplashScreen/Data/splash.gif b/QSplashScreen/Data/splash.gif new file mode 100644 index 0000000..8553388 Binary files /dev/null and b/QSplashScreen/Data/splash.gif differ diff --git a/QSplashScreen/GifSplashScreen.py b/QSplashScreen/GifSplashScreen.py new file mode 100644 index 0000000..6d17998 --- /dev/null +++ b/QSplashScreen/GifSplashScreen.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Created on 2020/6/11 +@author: Irony +@site: https://pyqt.site https://github.com/PyQt5 +@email: 892768447@qq.com +@file: +@description: +""" + +__Author__ = 'Irony' +__Copyright__ = 'Copyright (c) 2020' +__Version__ = 'Version 1.0' + +from PyQt5.QtCore import QTimer, Qt +from PyQt5.QtGui import QMovie +from PyQt5.QtWidgets import QApplication, QSplashScreen, QWidget + + +class GifSplashScreen(QSplashScreen): + + def __init__(self, *args, **kwargs): + super(GifSplashScreen, self).__init__(*args, **kwargs) + self.movie = QMovie('Data/splash.gif') + self.movie.frameChanged.connect(self.onFrameChanged) + self.movie.start() + + def onFrameChanged(self, _): + self.setPixmap(self.movie.currentPixmap()) + + def finish(self, widget): + self.movie.stop() + super(GifSplashScreen, self).finish(widget) + + +if __name__ == '__main__': + import sys + import cgitb + + cgitb.enable(1, None, 5, '') + + app = QApplication(sys.argv) + splash = GifSplashScreen() + splash.show() + + + def createWindow(): + app.w = QWidget() + # 模拟初始5秒后再显示 + splash.showMessage('等待界面显示', Qt.AlignHCenter | Qt.AlignBottom, Qt.white) + QTimer.singleShot(3000, lambda: ( + splash.showMessage('初始化完成', Qt.AlignHCenter | Qt.AlignBottom, Qt.white), app.w.show(), + splash.finish(app.w))) + + + # 模拟耗时5秒。但是不能用sleep + # 可以使用子线程加载耗时的数据 + # 主线程中循环设置UI可以配合QApplication.instance().processEvents() + splash.showMessage('等待创建界面', Qt.AlignHCenter | Qt.AlignBottom, Qt.white) + QTimer.singleShot(3000, createWindow) + + sys.exit(app.exec_()) diff --git a/QSplashScreen/README.en.md b/QSplashScreen/README.en.md new file mode 100644 index 0000000..e69de29 diff --git a/QSplashScreen/README.md b/QSplashScreen/README.md new file mode 100644 index 0000000..51da420 --- /dev/null +++ b/QSplashScreen/README.md @@ -0,0 +1,11 @@ +# QSplashScreen + +- 目录 + - [启动画面动画](#1启动画面动画) + +## 1、启动画面动画 +[运行 GifSplashScreen.py](GifSplashScreen.py) + +结合 `QMovie` 的 `frameChanged` 信号 不停地设置新的pixmap图片 + +![GifSplashScreen](ScreenShot/GifSplashScreen.gif) \ No newline at end of file diff --git a/QSplashScreen/ScreenShot/GifSplashScreen.gif b/QSplashScreen/ScreenShot/GifSplashScreen.gif new file mode 100644 index 0000000..0c22635 Binary files /dev/null and b/QSplashScreen/ScreenShot/GifSplashScreen.gif differ diff --git a/README.md b/README.md index dd55823..2253d4d 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,8 @@ https://pyqt.site 论坛是专门针对PyQt5学习和提升开设的网站,分 - [百分比进度条](QProgressBar/PercentProgressBar.py) - [Metro进度条](QProgressBar/MetroCircleProgress.py) - [水波纹进度条](QProgressBar/WaterProgressBar.py) + - [QSplashScreen](QSplashScreen) + - [启动画面动画](QSplashScreen/GifSplashScreen.py) - [QOpenGLWidget](QOpenGLWidget) - [QWebView](QWebView) - [梦幻树](QWebView/DreamTree.py)