边框动画阴影

This commit is contained in:
Irony 2018-09-25 23:31:08 +08:00
parent c2e0d0c7a5
commit 2001d9ad75
7 changed files with 117 additions and 1 deletions

View file

@ -97,6 +97,7 @@ encoding//\u754C\u9762\u7F8E\u5316/\u5404\u7C7B\u8FDB\u5EA6\u6761/PercentProgres
encoding//\u754C\u9762\u7F8E\u5316/\u6C34\u6CE2\u7EB9\u8FDB\u5EA6\u6761/ProgressBar.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/\u6C34\u6CE2\u7EB9\u8FDB\u5EA6\u6761/TestWidget.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/\u8FB9\u6846\u52A8\u753B\u9634\u5F71/AnimationShadowEffect.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/\u8FB9\u6846\u52A8\u753B\u9634\u5F71/Test.py=utf-8
encoding//\u7A0B\u5E8F\u91CD\u542F/AutoRestart.py=utf-8
encoding//\u7A97\u53E3\u91CD\u542F/RestartMainWindow.py=utf-8
encoding//\u7B80\u5355\u7684\u7A97\u53E3\u8D34\u8FB9\u9690\u85CF/WeltHideWindow.py=utf-8

View file

@ -106,6 +106,7 @@
1. - [ QPushButton进度动画](界面美化/QPushButton进度动画)
1. - [ QSlider美化](界面美化/QSlider美化)
1. - [ 各类进度条](界面美化/各类进度条)
1. - [ 动态边框阴影动画](界面美化/边框动画阴影)
#### 3.2 [动画类](动画特效/)
1. - [ 气泡提示 上升渐隐](消息提示/)

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View file

@ -9,9 +9,43 @@ Created on 2018年9月25日
@file: AnimationShadowEffect
@description: 边框动画阴影动画
"""
from PyQt5.QtCore import QPropertyAnimation, pyqtProperty
from PyQt5.QtWidgets import QGraphicsDropShadowEffect
__Author__ = """By: Irony
QQ: 892768447
Email: 892768447@qq.com"""
__Copyright__ = 'Copyright (c) 2018 Irony'
__Version__ = 1.0
__Version__ = 1.0
class AnimationShadowEffect(QGraphicsDropShadowEffect):
def __init__(self, color, *args, **kwargs):
super(AnimationShadowEffect, self).__init__(*args, **kwargs)
self.setColor(color)
self.setOffset(0, 0)
self.setBlurRadius(0)
self._radius = 0
self.animation = QPropertyAnimation(self)
self.animation.setTargetObject(self)
self.animation.setDuration(2000) # 一次循环时间
self.animation.setLoopCount(-1) # 永久循环
self.animation.setPropertyName(b'radius')
# 插入线行值
self.animation.setKeyValueAt(0, 1)
self.animation.setKeyValueAt(0.5, 30)
self.animation.setKeyValueAt(1, 1)
def start(self):
self.animation.start()
@pyqtProperty(int)
def radius(self):
return self._radius
@radius.setter
def radius(self, r):
self._radius = r
self.setBlurRadius(r)

View file

@ -0,0 +1,10 @@
# QGraphicsDropShadowEffect动态边框阴影动画
### 简单说明
- 1.通过setGraphicsEffect设置控件的边框阴影
- 2.继承QGraphicsDropShadowEffect实现增加动态属性radius
- 3.通过QPropertyAnimation属性动画不断改变radius的值并调用setBlurRadius更新半径值
截图
![1](ScreenShot/1.gif)

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 KiB

View file

@ -0,0 +1,70 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年9月25日
@author: Irony
@site: https://pyqt5.com, https://github.com/892768447
@email: 892768447@qq.com
@file: Test
@description:
"""
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QPushButton, QLineEdit
from AnimationShadowEffect import AnimationShadowEffect # @UnresolvedImport
__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)
layout = QHBoxLayout(self)
# 绿色边框
labelGreen = QLabel(self, pixmap=QPixmap('1.jpg').scaled(100, 100))
layout.addWidget(labelGreen)
aniGreen = AnimationShadowEffect(Qt.darkGreen, labelGreen)
labelGreen.setGraphicsEffect(aniGreen)
aniGreen.start()
# 红色边框,圆形图片
labelRed = QLabel(self)
labelRed.setMinimumSize(100, 100)
labelRed.setMaximumSize(100, 100)
labelRed.setStyleSheet('border-image: url(1.jpg);border-radius: 50px;')
layout.addWidget(labelRed)
aniRed = AnimationShadowEffect(Qt.red, labelGreen)
labelRed.setGraphicsEffect(aniRed)
aniRed.start()
# 蓝色边框按钮
button = QPushButton('按钮', self)
aniButton = AnimationShadowEffect(Qt.blue, button)
layout.addWidget(button)
button.setGraphicsEffect(aniButton)
aniButton.start()
# 青色边框输入框
lineedit = QLineEdit(self)
aniEdit = AnimationShadowEffect(Qt.cyan, lineedit)
layout.addWidget(lineedit)
lineedit.setGraphicsEffect(aniEdit)
aniEdit.start()
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())