Skip to content

Commit

Permalink
Animation
Browse files Browse the repository at this point in the history
  • Loading branch information
892768447 committed Dec 27, 2018
1 parent a49a423 commit a102b92
Show file tree
Hide file tree
Showing 36 changed files with 24 additions and 391 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<customwidget>
<class>SlidingStackedWidget</class>
<extends>QStackedWidget</extends>
<header location="global">SlidingStackedWidget</header>
<header location="global">Lib.SlidingStackedWidget</header>
<container>1</container>
</customwidget>
</customwidgets>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion 动画/窗口淡入淡出.py → Animation/FadeInOut.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# author: Irony
# site: https://pyqt5.com, https://github.com/892768447
# email: [email protected]
# file: 动画特效.淡入淡出
# file: FadeInOut
# description:
__Author__ = """By: Irony
QQ: 892768447
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@author: Irony
@site: https://pyqt5.com, https://github.com/892768447
@email: [email protected]
@file: 动画特效.右键菜单动画
@file: MenuAnimation
@description:
"""
from PyQt5.QtCore import QPropertyAnimation, QEasingCurve, QRect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
author: Irony
site: https://pyqt5.com , https://github.com/892768447
email: [email protected]
file:
file: PageSwitching
description:
"""
import os
Expand All @@ -15,7 +15,7 @@
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QLabel

from UiImageSlider import Ui_Form # @UnresolvedImport
from Lib.UiImageSlider import Ui_Form # @UnresolvedImport


__Author__ = """By: Irony
Expand Down Expand Up @@ -48,10 +48,10 @@ def __init__(self, *args, **kwargs):
self.pushButtonStop.clicked.connect(self.autoStop)

# 添加图片页面
for name in os.listdir('Images'):
for name in os.listdir('Data/Images'):
label = QLabel(self.stackedWidget)
label.setScaledContents(True)
label.setPixmap(QPixmap('Images/' + name))
label.setPixmap(QPixmap('Data/Images/' + name))
self.stackedWidget.addWidget(label)

def autoStart(self):
Expand Down
1 change: 1 addition & 0 deletions Animation/README.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Animation
54 changes: 13 additions & 41 deletions 动画/README.md → Animation/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# 动画特效
# Animation

使用QPropertyAnimation属性类动画(支持的属性有限)

## [1、窗口淡入淡出](窗口淡入淡出.py)
# 1、窗口淡入淡出
[运行 FadeInOut.py](FadeInOut.py)

1. 使用`QPropertyAnimation`对窗口的`windowOpacity`透明度属性进行修改
1. 窗口启动时开启透明度0-->1的动画
Expand All @@ -12,46 +11,18 @@
1. 停止就动画
1. 绑定动画完成后`finished`信号连接到`close`关闭窗口函数

![截图](ScreenShot/窗口淡入淡出.gif)
![FadeInOut](ScreenShot/FadeInOut.gif)

## [2、右键菜单动画](右键菜单动画.py)
# 2、右键菜单动画
[运行 MenuAnimation](MenuAnimation.py)

1. 使用`QPropertyAnimation`对菜单控件的`geometry`属性进行修改
1. 当菜单事件`contextMenuEvent`触发时调用动画启动,同时显示菜单

![截图](ScreenShot/右键菜单动画.gif)

## [3、按钮放大缩小动画](按钮放大缩小动画.py)

1. 使用`QPropertyAnimation`对按钮的`geometry`属性进行修改
1. 针对按钮在布局中或者没有在布局中两种情况,需要对主窗口的`showEvent``resizeEvent`两个事件进行重写,从而达到更新按钮的最新`geometry`
1. 主动调用按钮的`updatePos`函数来更新`geometry`

比如:

```python
def showEvent(self, event):
super(TestWindow, self).showEvent(event)
# 更新按钮的位置
self.button1.updatePos()
# 针对不在控件中的按钮
self.button2.move(self.width() - self.button2.width() - 15,
self.height() - self.button2.height() - 10)
self.button2.updatePos()

def resizeEvent(self, event):
super(TestWindow, self).resizeEvent(event)
# 更新按钮的位置
self.button1.updatePos()
# 针对不在控件中的按钮
self.button2.move(self.width() - self.button2.width() - 15,
self.height() - self.button2.height() - 10)
self.button2.updatePos()
```

![截图](ScreenShot/按钮放大缩小动画.gif)
![MenuAnimation](ScreenShot/MenuAnimation.gif)

## [4、点阵特效](点阵特效.py)
## 3、点阵特效
[运行 RlatticeEffect.py](RlatticeEffect.py)

1. emmm,我也不知道这个动画叫啥名字,反正就是仿照网页做的
1. 参考js源码,大概的原理就是:
Expand Down Expand Up @@ -123,9 +94,10 @@ def findClose(points):
p1.closest = closest
```

![截图](ScreenShot/点阵特效.gif)
![RlatticeEffect](ScreenShot/RlatticeEffect.gif)

## [5、图片轮播动画](多页面切换动画/图片轮播动画.py)
## 5、页面切换/图片轮播动画
[运行 PageSwitching.py](PageSwitching.py)

1. 使用`QPropertyAnimation``QStackedWidget`中的子控件进行pos位移操作实现动画切换特效
1. 主要代码参考http://qt.shoutwiki.com/wiki/Extending_QStackedWidget_for_sliding_page_animations_in_Qt
Expand All @@ -138,4 +110,4 @@ def findClose(points):
1. `setCurrentIndex` 切换到指定页
1. `autoStart(msec)` 轮播模式, 默认是3000毫秒

![截图](ScreenShot/图片轮播动画.gif)
![PageSwitching](ScreenShot/PageSwitching.gif)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@author: Irony
@site: https://pyqt5.com, https://github.com/892768447
@email: [email protected]
@file:
@file: RlatticeEffect
@description:
"""
from random import random
Expand All @@ -26,7 +26,7 @@


try:
import pointtool # @UnusedImport @UnresolvedImport
from Lib import pointtool # @UnusedImport @UnresolvedImport
getDistance = pointtool.getDistance
findClose = pointtool.findClose
except:
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion 动画/按钮放大缩小动画.py → Test/ButtomZoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@author: Irony
@site: http://pyqt5.com https://github.com/892768447
@email: [email protected]
@file:
@file: ButtomZoom
@description:
"""
from PyQt5.QtCore import QPropertyAnimation, QRect
Expand Down
File renamed without changes
Loading

0 comments on commit a102b92

Please sign in to comment.