diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index aea50ad..f387abf 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -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 diff --git a/README.md b/README.md index a9a1186..b815fbb 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ 1. - [ QPushButton进度动画](界面美化/QPushButton进度动画) 1. - [ QSlider美化](界面美化/QSlider美化) 1. - [ 各类进度条](界面美化/各类进度条) +1. - [ 动态边框阴影动画](界面美化/边框动画阴影) #### 3.2 [动画类](动画特效/) 1. - [ 气泡提示 上升渐隐](消息提示/) diff --git a/界面美化/边框动画阴影/1.jpg b/界面美化/边框动画阴影/1.jpg new file mode 100644 index 0000000..ca8d2ac Binary files /dev/null and b/界面美化/边框动画阴影/1.jpg differ diff --git a/界面美化/边框动画阴影/AnimationShadowEffect.py b/界面美化/边框动画阴影/AnimationShadowEffect.py index d3e4c7b..71cdc44 100644 --- a/界面美化/边框动画阴影/AnimationShadowEffect.py +++ b/界面美化/边框动画阴影/AnimationShadowEffect.py @@ -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 \ No newline at end of file +__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) diff --git a/界面美化/边框动画阴影/README.md b/界面美化/边框动画阴影/README.md new file mode 100644 index 0000000..f7f4620 --- /dev/null +++ b/界面美化/边框动画阴影/README.md @@ -0,0 +1,10 @@ +# QGraphicsDropShadowEffect动态边框阴影动画 + +### 简单说明 + - 1.通过setGraphicsEffect设置控件的边框阴影 + - 2.继承QGraphicsDropShadowEffect实现增加动态属性radius + - 3.通过QPropertyAnimation属性动画不断改变radius的值并调用setBlurRadius更新半径值 + +截图 + +![1](ScreenShot/1.gif) \ No newline at end of file diff --git a/界面美化/边框动画阴影/ScreenShot/1.gif b/界面美化/边框动画阴影/ScreenShot/1.gif new file mode 100644 index 0000000..87597a5 Binary files /dev/null and b/界面美化/边框动画阴影/ScreenShot/1.gif differ diff --git a/界面美化/边框动画阴影/Test.py b/界面美化/边框动画阴影/Test.py new file mode 100644 index 0000000..8e48fa3 --- /dev/null +++ b/界面美化/边框动画阴影/Test.py @@ -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_())