{"id":1582,"date":"2023-02-09T18:55:32","date_gmt":"2023-02-09T10:55:32","guid":{"rendered":"http:\/\/zhang.mba\/?p=1582"},"modified":"2023-02-09T19:19:31","modified_gmt":"2023-02-09T11:19:31","slug":"pyqt5huan-xing-jin-du-tiao","status":"publish","type":"post","link":"https:\/\/zhang.mba\/index.php\/2023\/02\/09\/18\/55\/32\/1582\/pyqt5huan-xing-jin-du-tiao\/python\/zhangzhiqi\/","title":{"rendered":"Pyqt5\u73af\u5f62\u8fdb\u5ea6\u6761"},"content":{"rendered":"<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\u73af\u5f62\u8fdb\u5ea6\u6761.py\n#  \/\/  Copyright (c) 2023.\n#  \/\/  @Time    : 2023\/2\/9   19:4:25\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\u73af\u5f62\u8fdb\u5ea6\u6761.py\n#  \/\/  @LastModified: 2023\/2\/9 \u4e0b\u53487:04\n#  \/\/  @ProjectName : PythonAll\n#  #-*-coding:utf-8-*-\nimport sys\nfrom PyQt5.QtCore import *\nfrom PyQt5.QtWidgets import *\nfrom PyQt5.QtGui import *\n\nclass CircularProgress(QWidget):\n    def __init__(self):\n        super().__init__()\n        # \u8bb0\u5f55\u89d2\u5ea6\n        self.angle = 90\n        # \u8fd9\u4e2a\u662f\u7528\u4e8e\u7ed8\u5236\u7684\uff0cangle\u624d\u662f\u771f\u5b9e\u7684\u89d2\u5ea6\n        self.drawAngle = self.angle\n        # \u8fdb\u5ea6\u6761\u5bbd\u5ea6\n        self.lineWidth = 20\n        # \u65f6\u95f4\u7ebf\u505a\u52a8\u753b\n        self.timeLine = QTimeLine(1000, self)\n        self.timeLine.frameChanged.connect(self.updateTimeline)\n\n        # \u6570\u5b57\u8f93\u5165\u6846\n        self.input = QSpinBox(self)\n        self.input.setRange(0, 360)\n        self.input.setValue(45)\n        self.input.setGeometry(10, 10, 90, 30)\n        # \u6309\u94ae\n        self.btn = QPushButton(&quot;Set&quot;, self)\n        self.btn.setGeometry(10, 45, 90, 30)\n        self.btn.clicked.connect(self.setAngle)\n        # \u900f\u660e\u6837\u5f0f\n        self.setStyleSheet(&quot;QSpinBox,QPushButton{background:transparent;border:1px solid black;}&quot;)\n\n    def updateTimeline(self, frame):\n        self.drawAngle = frame\n        self.update()\n\n    def setAngle(self):\n        self.drawAngle = self.angle\n        self.angle = self.input.value()\n        self.timeLine.stop()\n        self.timeLine.setFrameRange(self.drawAngle, self.angle)\n        # self.update()\n        self.timeLine.start()\n\n    def paintEvent(self, event):\n        # \u8fd9\u91cc\u6709\u4e2a\u95ee\u9898\u662f\uff0cpyqt5\u65e0\u6cd5\u9690\u5f0f\u5427QRect\u8f6c\u4e3aQRectF(PySide2\u53ef\u4ee5)\uff0c\u6240\u4ee5\u8fd9\u91cc\u76f4\u63a5\u7528QRectF\n        the_rect = QRectF(0, 0, self.width(), self.height())\n        if the_rect.isNull():\n            return\n        # \u753b\u7b14\n        painter = QPainter(self)\n        painter.fillRect(the_rect, QColor(&quot;darkCyan&quot;))\n        painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform, on=True)\n        # \u955c\u50cf\u7ffb\u8f6c\uff0c\u8fd9\u6837\u5c31\u662f\u987a\u65f6\u9488\n        painter.setViewport(self.width(), 0, -self.width(), self.height())\n\n        # path\u9ed8\u8ba4OddEvenFill\uff0c\u8fd9\u6837\u5c31\u586b\u5145\u4e24\u4e2a\u5706\u76f8\u4ea4\u7684\u90e8\u5206\n        the_path = QPainterPath()\n        the_path.addEllipse(the_rect.adjusted(1, 1, -1, -1))\n        the_path.addEllipse(the_rect.adjusted(\n            1 + self.lineWidth, 1 + self.lineWidth, -1 - self.lineWidth, -1 - self.lineWidth))\n        painter.fillPath(the_path, QColor(6, 79, 103))\n\n        # \u5f84\u5411\u6e10\u53d8\uff08\u53c2\u6570\u4e3a\u4e2d\u5fc3\u70b9\u548c\u8d77\u59cb\u89d2\u5ea6\uff09\uff0c\u9ed8\u8ba4\u65f6\u4ece\u53f3\u4fa7\u5f00\u59cb\u9006\u65f6\u9488\u7b97\u7684\n        the_gradient = QConicalGradient(the_rect.center(), 90)\n        the_angle = self.drawAngle \/ 360\n        the_gradient.setColorAt(0, QColor(255, 255, 0))\n        the_gradient.setColorAt(the_angle, QColor(255, 0, 255))\n        if the_angle + 0.001 &lt; 1:\n            the_gradient.setColorAt(the_angle + 0.001, QColor(0, 0, 0, 0))\n        painter.fillPath(the_path, the_gradient)\n\n\nif __name__ == &quot;__main__&quot;:\n    app = QApplication(sys.argv)\n    w = CircularProgress()\n    w.setWindowTitle(&quot;Untitle&quot;)\n    w.resize(400, 400)\n    w.show()\n    sys.exit(app.exec_())\n<\/code><\/pre>\n<p>\u6548\u679c\u56fe\uff1a<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16759409279365.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16759409279365.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># \/\/ \/Users\/zhangzhiqi\/Library\/Mobile Documents\/M6HJR9W95L~com~textasticapp~textastic\/Documents\/PycharmProjects\/PythonAll\/\u81ea\u5df1\u7684\/PyQt5\u6d4b\u8bd5\/Pyqt5\u73af\u5f62\u8fdb\u5ea6\u6761.py<\/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\/1582"}],"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=1582"}],"version-history":[{"count":0,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts\/1582\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/media?parent=1582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/categories?post=1582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/tags?post=1582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}