From 080bbf0d466f99ecdb11fd3e56e4a1141bb9d4b1 Mon Sep 17 00:00:00 2001 From: Irony <892768447@qq.com> Date: Tue, 4 Sep 2018 18:18:39 +0800 Subject: [PATCH] MaterialCircleProgress --- .settings/org.eclipse.core.resources.prefs | 1 + 界面美化/各类进度条/MaterialCircleProgress.py | 135 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 界面美化/各类进度条/MaterialCircleProgress.py diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 23aefd0..e4ead1c 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -88,6 +88,7 @@ encoding//\u754C\u9762\u7F8E\u5316/QScrollBar\u6EDA\u52A8\u6761\u6837\u5F0F/Scro encoding//\u754C\u9762\u7F8E\u5316/QSlider\u7F8E\u5316/PaintQSlider.py=utf-8 encoding//\u754C\u9762\u7F8E\u5316/QSlider\u7F8E\u5316/QssQSlider.py=utf-8 encoding//\u754C\u9762\u7F8E\u5316/\u5404\u7C7B\u8FDB\u5EA6\u6761/CircleProgressBar.py=utf-8 +encoding//\u754C\u9762\u7F8E\u5316/\u5404\u7C7B\u8FDB\u5EA6\u6761/MaterialCircleProgress.py=utf-8 encoding//\u754C\u9762\u7F8E\u5316/\u5404\u7C7B\u8FDB\u5EA6\u6761/PercentProgressBar.py=utf-8 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 diff --git a/界面美化/各类进度条/MaterialCircleProgress.py b/界面美化/各类进度条/MaterialCircleProgress.py new file mode 100644 index 0000000..2527875 --- /dev/null +++ b/界面美化/各类进度条/MaterialCircleProgress.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Created on 2018年9月4日 +@author: Irony +@site: https://github.com/892768447 +@email: 892768447@qq.com +@file: 界面美化.各类进度条.MaterialCircleProgress +@description: +""" +from PyQt5.QtCore import pyqtProperty, QSize, QParallelAnimationGroup,\ + QPropertyAnimation, QEasingCurve +from PyQt5.QtGui import QColor +from PyQt5.QtWidgets import QWidget + + +__Author__ = """By: Irony +QQ: 892768447 +Email: 892768447@qq.com""" +__Copyright__ = "Copyright (c) 2018 Irony" +__Version__ = "Version 1.0" + + +class MaterialCircleProgress(QWidget): + + BorderWidth = 6.25 # 边框宽度 + BorderColor = QColor(24, 189, 155) # 边框颜色 + DashLength = 0 + DashOffset = 0 + Angle = 0 + + def __init__(self, *args, **kwargs): + super(MaterialCircleProgress, self).__init__(*args, **kwargs) + self.initAnimation() + + def initAnimation(self): + # 动画组 + self._animationGroup = QParallelAnimationGroup(self, loopCount=-1) + + animation = QPropertyAnimation(self, b'dashLength', self) + animation.setEasingCurve(QEasingCurve.InOutQuad) + animation.setStartValue(0.1) + animation.setKeyValueAt(0.15, 0.2) + animation.setKeyValueAt(0.6, 20) + animation.setKeyValueAt(0.7, 20) + animation.setEndValue(20) + animation.setDuration(2050) + self._animationGroup.addAnimation(animation) + + animation = QPropertyAnimation(self, b'dashOffset', self) + animation.setEasingCurve(QEasingCurve.InOutSine) + animation.setStartValue(0) + animation.setKeyValueAt(0.15, 0) + animation.setKeyValueAt(0.6, -7) + animation.setKeyValueAt(0.7, -7) + animation.setEndValue(-25) + animation.setDuration(2050) + self._animationGroup.addAnimation(animation) + + animation = QPropertyAnimation(self, b'angle', self) + animation.setStartValue(0) + animation.setEndValue(719) + animation.setDuration(2050) + self._animationGroup.addAnimation(animation) + + self._animationGroup.start() + + @pyqtProperty(float) + def dashLength(self) -> float: + return self.DashLength + + @dashLength.setter + def dashLength(self, dashLength: float): + if self.DashLength != dashLength: + self.DashLength = dashLength + self.update() + + @pyqtProperty(float) + def dashOffset(self) -> float: + return self.DashOffset + + @dashOffset.setter + def dashOffset(self, dashOffset: float): + if self.DashOffset != dashOffset: + self.DashOffset = dashOffset + self.update() + + @pyqtProperty(int) + def angle(self) -> int: + return self.Angle + + @angle.setter + def angle(self, angle: int): + if self.Angle != angle: + self.Angle = angle + self.update() + + @pyqtProperty(float) + def borderWidth(self) -> float: + return self.BorderWidth + + @borderWidth.setter + def borderWidth(self, borderWidth: float): + if self.BorderWidth != borderWidth: + self.BorderWidth = borderWidth + self.update() + + @pyqtProperty(QColor) + def borderColor(self) -> QColor: + return self.BorderColor + + @borderColor.setter + def borderColor(self, borderColor: QColor): + if self.BorderColor != borderColor: + self.BorderColor = borderColor + self.update() + + def sizeHint(self) -> QSize: + return QSize(100, 100) + + +class Window(QWidget): + + def __init__(self, *args, **kwargs): + super(Window, self).__init__(*args, **kwargs) + + +if __name__ == '__main__': + import sys + from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) + w = Window() + w.show() + sys.exit(app.exec_())