Skip to content

Commit 393402d

Browse files
committed
启动画面动画
1 parent 0908e2d commit 393402d

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed

QSplashScreen/Data/splash.gif

653 KB
Loading

QSplashScreen/GifSplashScreen.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Created on 2020/6/11
6+
@author: Irony
7+
@site: https://pyqt.site https://github.com/PyQt5
8+
9+
@file:
10+
@description:
11+
"""
12+
13+
__Author__ = 'Irony'
14+
__Copyright__ = 'Copyright (c) 2020'
15+
__Version__ = 'Version 1.0'
16+
17+
from PyQt5.QtCore import QTimer, Qt
18+
from PyQt5.QtGui import QMovie
19+
from PyQt5.QtWidgets import QApplication, QSplashScreen, QWidget
20+
21+
22+
class GifSplashScreen(QSplashScreen):
23+
24+
def __init__(self, *args, **kwargs):
25+
super(GifSplashScreen, self).__init__(*args, **kwargs)
26+
self.movie = QMovie('Data/splash.gif')
27+
self.movie.frameChanged.connect(self.onFrameChanged)
28+
self.movie.start()
29+
30+
def onFrameChanged(self, _):
31+
self.setPixmap(self.movie.currentPixmap())
32+
33+
def finish(self, widget):
34+
self.movie.stop()
35+
super(GifSplashScreen, self).finish(widget)
36+
37+
38+
if __name__ == '__main__':
39+
import sys
40+
import cgitb
41+
42+
cgitb.enable(1, None, 5, '')
43+
44+
app = QApplication(sys.argv)
45+
splash = GifSplashScreen()
46+
splash.show()
47+
48+
49+
def createWindow():
50+
app.w = QWidget()
51+
# 模拟初始5秒后再显示
52+
splash.showMessage('等待界面显示', Qt.AlignHCenter | Qt.AlignBottom, Qt.white)
53+
QTimer.singleShot(3000, lambda: (
54+
splash.showMessage('初始化完成', Qt.AlignHCenter | Qt.AlignBottom, Qt.white), app.w.show(),
55+
splash.finish(app.w)))
56+
57+
58+
# 模拟耗时5秒。但是不能用sleep
59+
# 可以使用子线程加载耗时的数据
60+
# 主线程中循环设置UI可以配合QApplication.instance().processEvents()
61+
splash.showMessage('等待创建界面', Qt.AlignHCenter | Qt.AlignBottom, Qt.white)
62+
QTimer.singleShot(3000, createWindow)
63+
64+
sys.exit(app.exec_())

QSplashScreen/README.en.md

Whitespace-only changes.

QSplashScreen/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# QSplashScreen
2+
3+
- 目录
4+
- [启动画面动画](#1启动画面动画)
5+
6+
## 1、启动画面动画
7+
[运行 GifSplashScreen.py](GifSplashScreen.py)
8+
9+
结合 `QMovie``frameChanged` 信号 不停地设置新的pixmap图片
10+
11+
![GifSplashScreen](ScreenShot/GifSplashScreen.gif)
847 KB
Loading

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ https://pyqt.site 论坛是专门针对PyQt5学习和提升开设的网站,分
126126
- [百分比进度条](QProgressBar/PercentProgressBar.py)
127127
- [Metro进度条](QProgressBar/MetroCircleProgress.py)
128128
- [水波纹进度条](QProgressBar/WaterProgressBar.py)
129+
- [QSplashScreen](QSplashScreen)
130+
- [启动画面动画](QSplashScreen/GifSplashScreen.py)
129131
- [QOpenGLWidget](QOpenGLWidget)
130132
- [QWebView](QWebView)
131133
- [梦幻树](QWebView/DreamTree.py)

0 commit comments

Comments
 (0)