{"id":1586,"date":"2023-02-09T19:29:55","date_gmt":"2023-02-09T11:29:55","guid":{"rendered":"http:\/\/zhang.mba\/?p=1586"},"modified":"2023-02-09T19:32:45","modified_gmt":"2023-02-09T11:32:45","slug":"pyqt5jian-bian-yuan-huan-shui-bo-jin-du-tiaotou-mi","status":"publish","type":"post","link":"https:\/\/zhang.mba\/index.php\/2023\/02\/09\/19\/29\/55\/1586\/pyqt5jian-bian-yuan-huan-shui-bo-jin-du-tiaotou-mi\/python\/zhangzhiqi\/","title":{"rendered":"PyQt5\u6e10\u53d8\u5706\u73af\u6c34\u6ce2\u8fdb\u5ea6\u6761+\u900f\u660e\u6de1\u5165"},"content":{"rendered":"<p>\u4ee3\u7801\uff1a<\/p>\n<pre class=\"line-numbers\"><code class=\"language-python\"># \/\/  \/Users\/zhangzhiqi\/Library\/Mobile Documents\/M6HJR9W95L~com~textasticapp~textastic\/Documents\/PycharmProjects\/PythonAll\/\u81ea\u5df1\u7684\/PyQt5\u6d4b\u8bd5\/PyQt5\u6e10\u53d8\u5706\u73af\u6c34\u6ce2\u8fdb\u5ea6\u6761+\u900f\u660e\u6de1\u5165(\u591a\u7ebf\u7a0b\u4fe1\u53f7).py\n#  \/\/  Copyright (c) 2023.\n#  \/\/  @Time    : 2023\/2\/9   19:21:40\n#  \/\/  @Author : \u5f20\u7a1a\u7426\n#  \/\/  @Address: \u6e56\u5317\u7406\u5de5\u5b66\u9662\u817e\u9f99\u516c\u5bd3 5620\n#  \/\/  @Email   : zhang@zhang.mba \/ zhangzhiqi828@gmail.com \/ zhangzhiqi@lh83.onmicrosoft.com \/ 2272358828@qq.com\n#  \/\/  @File      : PyQt5\u6e10\u53d8\u5706\u73af\u6c34\u6ce2\u8fdb\u5ea6\u6761+\u900f\u660e\u6de1\u5165(\u591a\u7ebf\u7a0b\u4fe1\u53f7).py\n#  \/\/  @LastModified: 2023\/2\/9 \u4e0b\u53487:21\n#  \/\/  @ProjectName : PythonAll\n#  #-*-coding:utf-8-*-\nimport sys\nfrom PyQt5.QtCore import *\nfrom PyQt5.QtGui import *\nfrom PyQt5.QtWidgets import *\nimport math\ndef Animation(parent, type=b&quot;windowOpacity&quot;, from_value=0, to_value=1, ms=1000, connect=None):\n    anim = QPropertyAnimation(parent, type)\n    anim.setDuration(ms)\n    anim.setStartValue(from_value)\n    anim.setEndValue(to_value)\n    if connect:\n        anim.finished.connect(connect)\n    anim.start()\n    return anim\nclass ProgressThread(QThread):\n    signal = pyqtSignal()\n\n    def run(self):\n        for p in range(100):\n            self.signal.emit()\n            self.msleep(100)\nclass RoundProgress(QWidget):\n    m_waterOffset = 0.05\n    m_offset = 50\n    bg_color = QColor(255, 0, 0)\n    fsize = 10\n    def __init__(self, t, parent=None):\n        super(RoundProgress, self).__init__(parent)\n        self.resize(*t)\n        self.size = t\n        self.setWindowFlags(Qt.FramelessWindowHint)  # \u53bb\u8fb9\u6846\n        self.setAttribute(Qt.WA_TranslucentBackground)  # \u8bbe\u7f6e\u7a97\u53e3\u80cc\u666f\u900f\u660e\n        self.percent = 0\n        self.pen = QPen()\n        gradient = QConicalGradient(50, 50, 91)\n        gradient.setColorAt(0, QColor(255, 10, 10))\n        gradient.setColorAt(1, QColor(255, 201 ,14))\n        #gradient.setColorAt(0.5, QColor(255, 201 ,14))\n        self.pen.setBrush(gradient)  # \u8bbe\u7f6e\u753b\u5237\u6e10\u53d8\u6548\u679c\n        self.pen.setWidth(8)\n        self.pen.setCapStyle(Qt.RoundCap)\n        self.font = QFont()\n        self.font.setFamily(&quot;Share-TechMono&quot;) #Share-TechMono\n        self.font.setPointSize(self.size[0] \/\/ 4)\n    def paintEvent(self, event):\n        width, height = self.size\n        rect = QRectF(self.fsize, self.fsize, width-self.fsize*2, height-self.fsize*2)\n        painter = QPainter(self)\n        rotateAngle = 360 * self.percent \/ 100\n        # \u7ed8\u5236\u51c6\u5907\u5de5\u4f5c\uff0c\u542f\u7528\u53cd\u952f\u9f7f\n        painter.setRenderHints(QPainter.Antialiasing)\n        painter.setPen(self.pen)\n\n\n        painter.drawArc(rect, (90 - 0) * 16, -rotateAngle * 16)  # \u753b\u5706\u73af\n        painter.setFont(self.font)\n        painter.setPen(QColor(153 - 1.53*self.percent ,\n                              217-0.55*self.percent,\n                              234-0.02*self.percent)) # r:255, g:201 - 10\/100 * percent, b: 14-4 \/100*percent \u5f53\u524d\u6e10\u53d8\n        painter.drawText(rect, Qt.AlignCenter, &quot;%d%%&quot; % self.percent ) # \u663e\u793a\u8fdb\u5ea6\u6761\u5f53\u524d\u8fdb\u5ea6\n        self.update()\n    def update_percent(self, p):\n        self.percent = p\nclass WaterProgress(QWidget):\n    fsize = 10\n    def __init__(self,t,parent=None):\n        super(WaterProgress, self).__init__(parent)\n        self.setWindowFlags(Qt.FramelessWindowHint)  # \u53bb\u8fb9\u6846\n        self.setAttribute(Qt.WA_TranslucentBackground)  # \u8bbe\u7f6e\u7a97\u53e3\u80cc\u666f\u900f\u660e\n        self.resize(*t)\n        self.size = t\n        self.layout = QGridLayout(self)\n\n        #\u8bbe\u7f6e\u8fdb\u5ea6\u6761\u989c\u8272\n        self.bg_color = QColor(&quot;#95BBFF&quot;)\n        self.m_waterOffset = 0.005\n        self.m_offset = 50\n        self.m_borderwidth = 10\n        self.percent = 0\n    def paintEvent(self, event):\n        painter = QPainter()\n        painter.setRenderHint(QPainter.Antialiasing)\n        painter.begin(self)\n        painter.setPen(Qt.NoPen)\n        #\u83b7\u53d6\u7a97\u53e3\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\n        width,height = self.size\n        percentage = 1 - self.percent\/100\n        # \u6c34\u6ce2\u8d70\u5411\uff1a\u6b63\u5f26\u51fd\u6570 y = A(wx+l) + k\n        # w \u8868\u793a \u5468\u671f\uff0c\u503c\u8d8a\u5927\u5bc6\u5ea6\u8d8a\u5927\n        w = 2 * math.pi \/ (width)\n        # A \u8868\u793a\u632f\u5e45 \uff0c\u7406\u89e3\u4e3a\u6c34\u6ce2\u7684\u4e0a\u4e0b\u632f\u5e45\n        A = height * self.m_waterOffset\n        # k \u8868\u793a y \u7684\u504f\u79fb\u91cf\uff0c\u53ef\u7406\u89e3\u4e3a\u8fdb\u5ea6\n        k = height *percentage\n\n\n        water1 = QPainterPath()\n        water2 = QPainterPath()\n        #\u8d77\u59cb\u70b9\n        water1.moveTo(5,height)\n        water2.moveTo(5,height)\n        self.m_offset += 0.6\n\n        if(self.m_offset &gt;(width\/2)):\n            self.m_offset = 0\n        i = 5\n\n        rect = QRectF(self.fsize,self.fsize,width - self.fsize*2, height - self.fsize * 2)\n        while(i &lt; width-5):\n            waterY1 = A*math.sin(w*i +self.m_offset ) + k\n            waterY2 = A*math.sin(w*i + self.m_offset + width\/2*w) + k\n\n            water1.lineTo(i, waterY1)\n            water2.lineTo(i, waterY2)\n            i += 1\n\n        water1.lineTo(width-5,height)\n        water2.lineTo(width-5,height)\n\n        totalpath = QPainterPath()\n        #totalpath.addRect(rect)\n        #painter.setBrush(Qt.gray)\n        painter.drawRect(self.rect())\n        painter.save()\n        totalpath.addEllipse(rect)\n        totalpath.intersected(water1)\n        painter.setPen(Qt.NoPen)\n\n        #\u8bbe\u7f6e\u6c34\u6ce2\u7684\u900f\u660e\u5ea6\n        watercolor1 =QColor(self.bg_color)\n        watercolor1.setAlpha(100)\n        watercolor2 = QColor(self.bg_color)\n        watercolor2.setAlpha(150)\n        path = totalpath.intersected(water1)\n        painter.setBrush(watercolor1)\n        painter.drawPath(path)\n\n\n        path = totalpath.intersected(water2)\n        painter.setBrush(watercolor2)\n        painter.drawPath(path)\n        painter.restore()\n        painter.end()\n        #self.update()\n    def update_percent(self, p):\n        self.percent = p\n        if self.m_waterOffset &lt; 0.05:\n            self.m_waterOffset += 0.001\n        return p\nclass Progress(QDialog):\n    percent = 0\n    def __init__(self, text=&quot;&quot;,parent=None):\n        super(Progress, self).__init__(parent)\n        Font = QFont()\n        Font.setFamily(&quot;Consolas&quot;)\n        Font.setPointSize(12)\n        self.setFont(Font)\n        self.setWindowFlags(Qt.FramelessWindowHint)  # \u53bb\u8fb9\u6846\n        self.setAttribute(Qt.WA_TranslucentBackground)  # \u8bbe\u7f6e\u7a97\u53e3\u80cc\u666f\u900f\u660e\n        self.ProgressThread = ProgressThread()\n        self.ProgressThread.signal.connect(self.percentUpdate)\n        self.ProgressThread.start()\n        width, height = 230, 230\n        self.resize(width, height)\n        self.water = WaterProgress((width, height), self)\n        self.round = RoundProgress((width, height), self)\n        self.label = QLabel(self)\n        self.label.setText(QCoreApplication.translate(&quot;Dialog&quot;, text))\n        print(self.label.width())\n        self.label.move((width-self.label.width())\/2, height\/3*2)\n        QMetaObject.connectSlotsByName(self)\n        self.anim = Animation(self, )\n    def connect(self, link):\n        print(type(link))\n        #self.setWindowFlags(Qt.WindowStaysOnTopHint) #\u7f6e\u9876\n        self.show()\n    def percentUpdate(self):\n        self.percent += 1\n        self.water.update_percent(self.percent)\n        self.water.paintEvent(None)\n        self.round.update_percent(self.percent)\nif __name__ == '__main__':\n    app = QApplication(sys.argv)\n    r = Progress(&quot;&lt;a link='b'&gt;write something&lt;\/a&gt;&quot;)\n    r.show()\n    sys.exit(app.exec_())\n<\/code><\/pre>\n<p>\u6548\u679c\uff1a<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16759422598117.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16759422598117.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16759423475154.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16759423475154.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16759423144935.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16759423144935.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>\u4ee3\u7801\uff1a # \/\/ \/Users\/zhangzhiqi\/Library\/Mobile Documents\/M6HJR9W95L~com~textasticapp~textastic\/Documents\/PycharmProjects\/PythonAll\/\u81ea\u5df1\u7684\/PyQt5\u6d4b\u8bd5\/PyQt5\u6e10\u53d8\u5706\u73af\u6c34\u6ce2\u8fdb\u5ea6\u6761+\u900f\u660e\u6de1\u5165(\u591a\u7ebf\u7a0b\u4fe1\u53f7).py # \/\/ Copyright (c) 2023. # \/\/ @Time &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[58,12],"tags":[],"_links":{"self":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts\/1586"}],"collection":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/comments?post=1586"}],"version-history":[{"count":0,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts\/1586\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/media?parent=1586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/categories?post=1586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/tags?post=1586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}