淡入淡出
This commit is contained in:
parent
ceaca3a67b
commit
520bb94047
5 changed files with 72 additions and 0 deletions
|
@ -38,6 +38,7 @@ encoding//\u4EFFQQ\u8BBE\u7F6E\u9762\u677F/SettingUi.py=utf-8
|
|||
encoding//\u4EFFQQ\u8BBE\u7F6E\u9762\u677F/Window.py=utf-8
|
||||
encoding//\u5168\u5C40\u70ED\u952E/HotKey.py=utf-8
|
||||
encoding//\u5206\u5272\u7A97\u53E3\u7684\u5206\u5272\u6761\u91CD\u5199/Splitter.py=utf-8
|
||||
encoding//\u52A8\u753B\u7279\u6548/\u6DE1\u5165\u6DE1\u51FA.py=utf-8
|
||||
encoding//\u53F3\u4E0B\u89D2\u5F39\u51FA\u6846/WindowNotify.py=utf-8
|
||||
encoding//\u56FE\u7247\u52A0\u8F7D/LoadImage.py=utf-8
|
||||
encoding//\u56FE\u7247\u52A0\u8F7D/res_rc.py=utf-8
|
||||
|
|
|
@ -65,6 +65,9 @@
|
|||
- [4.9 水波纹进度条](界面美化/水波纹进度条)
|
||||
- [4.10 QSlider美化](界面美化/QSlider美化)
|
||||
|
||||
### [5.动画特效](动画特效/)
|
||||
- [5.1 淡入淡出](动画特效/淡入淡出.py)
|
||||
|
||||
# QQ群
|
||||
- [PyQt & PySide](https://jq.qq.com/?_wv=1027&k=50LWvn9)
|
||||
- [PyQt学习互助](https://jq.qq.com/?_wv=1027&k=5QVVEdF)
|
||||
|
|
7
动画特效/README.md
Normal file
7
动画特效/README.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# 简单的动画特效
|
||||
|
||||
使用QPropertyAnimation属性类动画(支持的属性有限)
|
||||
|
||||
### 常见例子
|
||||
- [1.1 淡入淡出](淡入淡出.py)<br/>
|
||||
![截图](ScreenShot/1.gif)
|
BIN
动画特效/ScreenShot/1.gif
Normal file
BIN
动画特效/ScreenShot/1.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 630 KiB |
61
动画特效/淡入淡出.py
Normal file
61
动画特效/淡入淡出.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
from PyQt5.QtCore import QPropertyAnimation
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton
|
||||
|
||||
|
||||
# Created on 2018年6月14日
|
||||
# author: Irony
|
||||
# site: https://github.com/892768447
|
||||
# email: 892768447@qq.com
|
||||
# file: 动画特效.淡入淡出
|
||||
# description:
|
||||
__Author__ = """By: Irony
|
||||
QQ: 892768447
|
||||
Email: 892768447@qq.com"""
|
||||
__Copyright__ = 'Copyright (c) 2018 Irony'
|
||||
__Version__ = 1.0
|
||||
|
||||
|
||||
class Window(QWidget):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Window, self).__init__(*args, **kwargs)
|
||||
self.resize(400, 400)
|
||||
layout = QVBoxLayout(self)
|
||||
layout.addWidget(QPushButton('退出', self, clicked=self.doClose))
|
||||
|
||||
# 窗口透明度动画类
|
||||
self.animation = QPropertyAnimation(self, b'windowOpacity')
|
||||
self.animation.setDuration(1000) # 持续时间1秒
|
||||
|
||||
# 执行淡入
|
||||
self.doShow()
|
||||
|
||||
def doShow(self):
|
||||
try:
|
||||
self.animation.finished.disconnect(self.close)
|
||||
except:
|
||||
pass
|
||||
self.animation.stop()
|
||||
# 透明度范围从0逐渐增加到1
|
||||
self.animation.setStartValue(0)
|
||||
self.animation.setEndValue(1)
|
||||
self.animation.start()
|
||||
|
||||
def doClose(self):
|
||||
self.animation.stop()
|
||||
self.animation.finished.connect(self.close) # 动画完成则关闭窗口
|
||||
# 透明度范围从1逐渐减少到0
|
||||
self.animation.setStartValue(1)
|
||||
self.animation.setEndValue(0)
|
||||
self.animation.start()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
app = QApplication(sys.argv)
|
||||
w = Window()
|
||||
w.show()
|
||||
sys.exit(app.exec_())
|
Loading…
Reference in a new issue