提交 7a313bf9 编写于 作者: 之一Yo's avatar 之一Yo

添加圆形进度条

上级 5362613c
PyQt5>=5.15.0
PyQt5-Frameless-Window
darkdetect
colorthief
scipy
pillow
sphinx-markdown-tables==0.0.17
sphinx-intl
furo
sphinx-autoapi
sphinx-copybutton
sphinx_design
urllib3<2.0.0
\ No newline at end of file
......@@ -707,6 +707,14 @@
<translation>添加到</translation>
</message>
</context>
<context>
<name>ProgressWidget</name>
<message>
<location filename="../../view/status_info_interface.py" line="265"/>
<source>Progress</source>
<translation>进度</translation>
</message>
</context>
<context>
<name>ScrollInterface</name>
<message>
......@@ -921,7 +929,7 @@
<translation>带有工具提示的标签</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="181"/>
<location filename="../../view/status_info_interface.py" line="175"/>
<source>Show StateToolTip</source>
<translation>显示进度提示条</translation>
</message>
......@@ -936,22 +944,22 @@
<translation>简单工具提示</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="179"/>
<location filename="../../view/status_info_interface.py" line="173"/>
<source>The model training is complete!</source>
<translation>模型训练完成啦</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="185"/>
<location filename="../../view/status_info_interface.py" line="179"/>
<source>Training model</source>
<translation>正在训练模型</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="185"/>
<location filename="../../view/status_info_interface.py" line="179"/>
<source>Please wait patiently</source>
<translation>心急吃不了热豆腐请耐心等待哦~</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="187"/>
<location filename="../../view/status_info_interface.py" line="181"/>
<source>Hide StateToolTip</source>
<translation>隐藏进度提示条</translation>
</message>
......@@ -996,17 +1004,17 @@
<translation>不同弹出位置的消息条</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="226"/>
<location filename="../../view/status_info_interface.py" line="220"/>
<source>No Internet</source>
<translation>无网络连接</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="204"/>
<location filename="../../view/status_info_interface.py" line="198"/>
<source>Lesson 4</source>
<translation>Lesson 4</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="215"/>
<location filename="../../view/status_info_interface.py" line="209"/>
<source>Lesson 5</source>
<translation>Lesson 5</translation>
</message>
......@@ -1016,27 +1024,27 @@
<translation>我的名字是吉良吉影年龄33岁家住杜王町东北部别墅区未婚我在龟友百货连锁公司上班每天最晚也是八点前回家不吸烟酒也是浅尝辄止晚上十一点上床保证八个小时的充足睡眠睡前喝一杯热牛奶再做二十分钟伸展运动暖身然后再睡觉基本可以熟睡到天亮像婴儿一样不留下疲劳与压力迎来第二天的早晨健康检查结果也显示我很健康我的意思是我是一个随时都想追求平静生活的人不拘泥于胜负与烦恼不树立令我夜不能寐的敌人这就是我对于这个社会的生活态度我也清楚这就是我的幸福</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="192"/>
<location filename="../../view/status_info_interface.py" line="186"/>
<source>Lesson 3</source>
<translation>Lesson 3</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="192"/>
<location filename="../../view/status_info_interface.py" line="186"/>
<source>Believe in the spin, just keep believing!</source>
<translation>相信回旋吧只管相信就是了</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="204"/>
<location filename="../../view/status_info_interface.py" line="198"/>
<source>With respect, let&apos;s advance towards a new stage of the spin.</source>
<translation>表达敬意吧表达出敬意然后迈向回旋的另一个全新阶段</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="215"/>
<location filename="../../view/status_info_interface.py" line="209"/>
<source>迂回路を行けば最短ルート</source>
<translation>最短的捷径就是绕远路绕远路才是我的最短捷径</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="226"/>
<location filename="../../view/status_info_interface.py" line="220"/>
<source>An error message which won&apos;t disappear automatically.</source>
<translation>一条不会自动消失的消息</translation>
</message>
......@@ -1081,22 +1089,22 @@
<translation>左下角</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="237"/>
<location filename="../../view/status_info_interface.py" line="231"/>
<source>Lesson 1</source>
<translation>Lesson 1</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="237"/>
<location filename="../../view/status_info_interface.py" line="231"/>
<source>Don&apos;t have any strange expectations of me.</source>
<translation>别对我抱有什么奇怪的期待</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="248"/>
<location filename="../../view/status_info_interface.py" line="242"/>
<source>Lesson 2</source>
<translation>Lesson 2</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="248"/>
<location filename="../../view/status_info_interface.py" line="242"/>
<source>Don&apos;t let your muscles notice.</source>
<translation>不要让肌肉察觉</translation>
</message>
......@@ -1106,15 +1114,15 @@
<translation>不确定进度条</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="165"/>
<source>Progress</source>
<translation>进度</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="170"/>
<location filename="../../view/status_info_interface.py" line="155"/>
<source>An determinate progress bar</source>
<translation>确定的进度条</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="165"/>
<source>An determinate progress ring</source>
<translation>确定的圆形进度条</translation>
</message>
</context>
<context>
<name>TableFrame</name>
......
......@@ -707,6 +707,14 @@
<translation>添加到</translation>
</message>
</context>
<context>
<name>ProgressWidget</name>
<message>
<location filename="../../view/status_info_interface.py" line="265"/>
<source>Progress</source>
<translation>進度</translation>
</message>
</context>
<context>
<name>ScrollInterface</name>
<message>
......@@ -921,7 +929,7 @@
<translation>帶有工具提示的標籤</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="181"/>
<location filename="../../view/status_info_interface.py" line="175"/>
<source>Show StateToolTip</source>
<translation>顯示進度提示條</translation>
</message>
......@@ -936,22 +944,22 @@
<translation>簡單工具提示</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="179"/>
<location filename="../../view/status_info_interface.py" line="173"/>
<source>The model training is complete!</source>
<translation>模型訓練完成啦</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="185"/>
<location filename="../../view/status_info_interface.py" line="179"/>
<source>Training model</source>
<translation>正在訓練模型</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="185"/>
<location filename="../../view/status_info_interface.py" line="179"/>
<source>Please wait patiently</source>
<translation>心急吃不了熱豆腐請耐心等待哦~</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="187"/>
<location filename="../../view/status_info_interface.py" line="181"/>
<source>Hide StateToolTip</source>
<translation>隱藏進度提示條</translation>
</message>
......@@ -996,47 +1004,47 @@
<translation>不同彈出位置的消息條</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="226"/>
<location filename="../../view/status_info_interface.py" line="220"/>
<source>No Internet</source>
<translation>無網絡連接</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="204"/>
<location filename="../../view/status_info_interface.py" line="198"/>
<source>Lesson 4</source>
<translation>Lesson 4</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="215"/>
<location filename="../../view/status_info_interface.py" line="209"/>
<source>Lesson 5</source>
<translation>Lesson 5</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="75"/>
<source>My name is kira yoshikake, 33 years old. Living in the villa area northeast of duwangting, unmarried. I work in Guiyou chain store. Every day I have to work overtime until 8 p.m. to go home. I don&apos;t smoke. The wine is only for a taste. Sleep at 11 p.m. for 8 hours a day. Before I go to bed, I must drink a cup of warm milk, then do 20 minutes of soft exercise, get on the bed, and immediately fall asleep. Never leave fatigue and stress until the next day. Doctors say I&apos;m normal.</source>
<translation>我的名字叫吉良吉影33住在杜王町東北部的別墅區一帶未婚我在龜友連鎖店服務每天都要加班到晚上8點才能回家我不抽煙酒僅止於淺嘗晚上11點睡每天要睡足8個小時睡前我一定喝一杯温牛奶然後做20分鐘的柔軟操上了牀馬上熟睡一覺到天亮決不把疲勞和壓力留到第二天醫生都説我很正常</translation>
<translation>我的名字是吉良吉影年齡33歲家住杜王町東北部別墅區未婚我在龜友百貨連鎖公司上班每天最晚也是八點前回家不吸煙酒也是淺嘗輒止晚上十一點上牀保證八個小時的充足睡眠睡前喝一杯熱牛奶再做二十分鐘伸展運動暖身然後再睡覺基本可以熟睡到天亮像嬰兒一樣不留下疲勞與壓力迎來第二天的早晨健康檢查結果也顯示我很健康我的意思是我是一個隨時都想追求平靜生活的人不拘泥於勝負與煩惱不樹立令我夜不能寐的敵人這就是我對於這個社會的生活態度我也清楚這就是我的幸福</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="192"/>
<location filename="../../view/status_info_interface.py" line="186"/>
<source>Lesson 3</source>
<translation>Lesson 3</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="192"/>
<location filename="../../view/status_info_interface.py" line="186"/>
<source>Believe in the spin, just keep believing!</source>
<translation>相信迴旋吧只管相信就是了</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="204"/>
<location filename="../../view/status_info_interface.py" line="198"/>
<source>With respect, let&apos;s advance towards a new stage of the spin.</source>
<translation>表達敬意吧表達出敬意然後邁向迴旋的另一個全新階段</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="215"/>
<location filename="../../view/status_info_interface.py" line="209"/>
<source>迂迴路を行けば最短ルート</source>
<translation>最短的捷徑就是繞遠路繞遠路才是我的最短捷徑</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="226"/>
<location filename="../../view/status_info_interface.py" line="220"/>
<source>An error message which won&apos;t disappear automatically.</source>
<translation>一條不會自動消失的消息</translation>
</message>
......@@ -1081,22 +1089,22 @@
<translation>左下角</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="237"/>
<location filename="../../view/status_info_interface.py" line="231"/>
<source>Lesson 1</source>
<translation>Lesson 1</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="237"/>
<location filename="../../view/status_info_interface.py" line="231"/>
<source>Don&apos;t have any strange expectations of me.</source>
<translation>別對我抱有什麼奇怪的期待</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="248"/>
<location filename="../../view/status_info_interface.py" line="242"/>
<source>Lesson 2</source>
<translation>Lesson 2</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="248"/>
<location filename="../../view/status_info_interface.py" line="242"/>
<source>Don&apos;t let your muscles notice.</source>
<translation>不要讓肌肉察覺</translation>
</message>
......@@ -1106,15 +1114,15 @@
<translation>不確定進度條</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="165"/>
<source>Progress</source>
<translation>進度</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="170"/>
<location filename="../../view/status_info_interface.py" line="155"/>
<source>An determinate progress bar</source>
<translation>確定的進度條</translation>
</message>
<message>
<location filename="../../view/status_info_interface.py" line="165"/>
<source>An determinate progress ring</source>
<translation>確定的圓形進度條</translation>
</message>
</context>
<context>
<name>TableFrame</name>
......
......@@ -33,7 +33,7 @@ ExampleCard>#card {
ExampleCard>#card QLabel {
font: 14px 'Segoe UI', 'Microsoft YaHei';
color: black;
color: white;
}
ExampleCard>#titleLabel {
......
......@@ -290,18 +290,10 @@ class HomeInterface(ScrollArea):
icon=":/gallery/images/controls/ProgressRing.png",
title="StateToolTip",
content=self.tr(
"Shows the apps progress on a task,or that the app is performing ongoing work that does block user interaction."),
"Shows the apps progress on a task, or that the app is performing ongoing work that does block user interaction."),
routeKey="statusInfoInterface",
index=0
)
stateInfoView.addSampleCard(
icon=":/gallery/images/controls/ToolTip.png",
title="ToolTip",
content=self.tr(
"Displays information for an element in a pop-up window."),
routeKey="statusInfoInterface",
index=1
)
stateInfoView.addSampleCard(
icon=":/gallery/images/controls/InfoBar.png",
title="InfoBar",
......@@ -318,6 +310,22 @@ class HomeInterface(ScrollArea):
routeKey="statusInfoInterface",
index=7
)
stateInfoView.addSampleCard(
icon=":/gallery/images/controls/ProgressRing.png",
title="ProgressRing",
content=self.tr(
"Shows the apps progress on a task, or that the app is performing ongoing work that doesn't block user interaction."),
routeKey="statusInfoInterface",
index=9
)
stateInfoView.addSampleCard(
icon=":/gallery/images/controls/ToolTip.png",
title="ToolTip",
content=self.tr(
"Displays information for an element in a pop-up window."),
routeKey="statusInfoInterface",
index=1
)
self.vBoxLayout.addWidget(stateInfoView)
# text samples
......
......@@ -4,7 +4,7 @@ from PyQt5.QtGui import QPixmap, QColor
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QVBoxLayout
from qfluentwidgets import (StateToolTip, ToolTipFilter, PushButton, PixmapLabel,
InfoBar, InfoBarIcon, FluentIcon, InfoBarPosition, ProgressBar,
IndeterminateProgressBar, SpinBox)
IndeterminateProgressBar, SpinBox, ProgressRing)
from .gallery_interface import GalleryInterface
from ..common.translator import Translator
......@@ -150,29 +150,23 @@ class StatusInfoInterface(GalleryInterface):
card.topLayout.setContentsMargins(12, 24, 12, 24)
# progress bar
w = QWidget(self)
hBoxLayout = QHBoxLayout(w)
bar = ProgressBar(self)
bar.setFixedWidth(200)
spinBox = SpinBox(self)
spinBox.valueChanged.connect(bar.setValue)
spinBox.setRange(0, 100)
hBoxLayout.addWidget(bar)
hBoxLayout.addSpacing(50)
hBoxLayout.addWidget(QLabel(self.tr('Progress')))
hBoxLayout.addSpacing(5)
hBoxLayout.addWidget(spinBox)
hBoxLayout.setContentsMargins(0, 0, 0, 0)
self.addExampleCard(
self.tr('An determinate progress bar'),
w,
ProgressWidget(bar, self),
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/progress_bar/demo.py',
)
# progress ring
ring = ProgressRing(self)
ring.setFixedSize(80, 80)
ring.setTextVisible(True)
self.addExampleCard(
self.tr('An determinate progress ring'),
ProgressWidget(ring, self),
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/progress_ring/demo.py',
)
def onStateButtonClicked(self):
if self.stateTooltip:
......@@ -254,3 +248,23 @@ class StatusInfoInterface(GalleryInterface):
duration=1500, # won't disappear automatically
parent=self
)
class ProgressWidget(QWidget):
def __init__(self, widget, parent=None):
super().__init__(parent=parent)
hBoxLayout = QHBoxLayout(self)
self.spinBox = SpinBox(self)
self.spinBox.valueChanged.connect(widget.setValue)
self.spinBox.setRange(0, 100)
hBoxLayout.addWidget(widget)
hBoxLayout.addSpacing(50)
hBoxLayout.addWidget(QLabel(self.tr('Progress')))
hBoxLayout.addSpacing(5)
hBoxLayout.addWidget(self.spinBox)
hBoxLayout.setContentsMargins(0, 0, 0, 0)
self.spinBox.setValue(0)
# coding:utf-8
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout
from qfluentwidgets import ProgressRing, SpinBox, setTheme, Theme
class Demo(QWidget):
def __init__(self):
super().__init__()
# setTheme(Theme.DARK)
# self.setStyleSheet('Demo{background: rgb(32, 32, 32)}')
self.vBoxLayout = QHBoxLayout(self)
self.progressRing = ProgressRing(self)
self.spinBox = SpinBox(self)
self.progressRing.setValue(50)
self.progressRing.setTextVisible(True)
self.progressRing.setFixedSize(80, 80)
# change background color
# self.progressRing.setCustomBackgroundColor(Qt.transparent, Qt.transparent)
# change font
# font = QFont()
# font.setFamilies(['Segoe UI', 'Microsoft YaHei'])
# font.setPixelSize(15)
# self.progressRing.setFont(font)
self.spinBox.setRange(0, 100)
self.spinBox.setValue(50)
self.spinBox.valueChanged.connect(self.progressRing.setValue)
self.vBoxLayout.addWidget(self.progressRing, 0, Qt.AlignCenter)
self.vBoxLayout.addWidget(self.spinBox, 0, Qt.AlignCenter)
self.vBoxLayout.setContentsMargins(30, 30, 30, 30)
self.resize(400, 400)
if __name__ == '__main__':
# enable dpi scale
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
app = QApplication(sys.argv)
w = Demo()
w.show()
app.exec_()
\ No newline at end of file
......@@ -20,4 +20,5 @@ from .tool_tip import ToolTip, ToolTipFilter, ToolTipPosition
from .tree_view import TreeWidget, TreeView, TreeItemDelegate
from .cycle_list_widget import CycleListWidget
from .progress_bar import IndeterminateProgressBar, ProgressBar
from .progress_ring import ProgressRing
from .scroll_bar import ScrollBar, SmoothScrollBar, SmoothScrollDelegate
\ No newline at end of file
......@@ -2,9 +2,9 @@
from math import floor
from PyQt5.QtCore import (QEasingCurve, Qt, pyqtSignal, QPropertyAnimation, pyqtProperty,
QParallelAnimationGroup, QSequentialAnimationGroup)
QParallelAnimationGroup, QSequentialAnimationGroup, QLocale)
from PyQt5.QtGui import QPainter, QColor
from PyQt5.QtWidgets import QProgressBar, QWidget
from PyQt5.QtWidgets import QProgressBar
from ...common.style_sheet import themeColor, isDarkTheme
......@@ -12,27 +12,118 @@ from ...common.style_sheet import themeColor, isDarkTheme
class ProgressBar(QProgressBar):
def __init__(self, parent=None):
def __init__(self, parent=None, useAni=True):
super().__init__(parent)
self._val = 0
self.setFixedHeight(4)
self.useAni = useAni
self.lightBackgroundColor = QColor(0, 0, 0, 155)
self.darkBackgroundColor = QColor(255, 255, 255, 155)
self.ani = QPropertyAnimation(self, b'val', self)
self._isPaused = False
self._isError = False
self.setValue(0)
@pyqtProperty(float)
def val(self):
return self._val
@val.setter
def val(self, v):
self._val = v
self.update()
def setValue(self, value: int):
if not self.useAni:
self._val = value
return super().setValue(value)
self.ani.stop()
self.ani.setStartValue(self.value())
self.ani.setEndValue(value)
self.ani.setDuration(150)
self.ani.start()
super().setValue(value)
def setCustomBackgroundColor(self, light, dark):
""" set the custom background color
Parameters
----------
light, dark: str | Qt.GlobalColor | QColor
background color in light/dark theme mode
"""
self.lightBackgroundColor = QColor(light)
self.darkBackgroundColor = QColor(dark)
self.update()
def resume(self):
self._isPaused = False
self._isError = False
self.update()
def pause(self):
self._isPaused = True
self.update()
def setPaused(self, isPaused: bool):
self._isPaused = isPaused
self.update()
def isPaused(self):
return self._isPaused
def error(self):
self._isError = True
self.update()
def setError(self, isError: bool):
self._isError = isError
if isError:
self.error()
else:
self.resume()
def isError(self):
return self._isError
def valText(self):
if self.maximum() <= self.minimum():
return ""
total = self.maximum() - self.minimum()
result = self.format()
locale = self.locale()
locale.setNumberOptions(locale.numberOptions()
| QLocale.OmitGroupSeparator)
result = result.replace("%m", locale.toString(total))
result = result.replace("%v", locale.toString(self.val))
if total == 0:
return result.replace("%p", locale.toString(100))
progress = int((self.val - self.minimum()) * 100 / total)
return result.replace("%p", locale.toString(progress))
def paintEvent(self, e):
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing)
# draw background
c = 255 if isDarkTheme() else 0
painter.setPen(QColor(c, c, c, 155))
bc = self.darkBackgroundColor if isDarkTheme() else self.lightBackgroundColor
painter.setPen(bc)
y = floor(self.height() / 2)
painter.drawLine(0, y, self.width(), y)
if self.minimum() == self.maximum():
if self.minimum() >= self.maximum():
return
# draw bar
painter.setPen(Qt.NoPen)
painter.setBrush(themeColor())
w = int(self.value() / (self.maximum() - self.minimum()) * self.width())
w = int(self.val / (self.maximum() - self.minimum()) * self.width())
r = self.height() / 2
painter.drawRoundedRect(0, 0, w, self.height(), r, r)
......@@ -57,7 +148,7 @@ class IndeterminateProgressBar(QProgressBar):
self.shortBarAni.setStartValue(0)
self.longBarAni.setStartValue(0)
self.shortBarAni.setEndValue(1.45)
self.longBarAni.setEndValue(1.65)
self.longBarAni.setEndValue(1.75)
self.longBarAni.setEasingCurve(QEasingCurve.OutQuad)
self.aniGroup.addAnimation(self.shortBarAni)
......
# coding:utf-8
from PyQt5.QtCore import Qt, QRectF
from PyQt5.QtGui import QColor, QPen, QPainter, QFont
from .progress_bar import ProgressBar
from ...common.style_sheet import themeColor, isDarkTheme
class ProgressRing(ProgressBar):
""" Progress ring """
def __init__(self, parent=None, useAni=True):
super().__init__(parent, useAni=useAni)
self.lightBackgroundColor = QColor(0, 0, 0, 34)
self.darkBackgroundColor = QColor(255, 255, 255, 34)
self.setTextVisible(False)
self.setFixedSize(100, 100)
font = QFont()
font.setFamilies(['Segoe UI', 'Microsoft YaHei'])
font.setPixelSize(14)
self.setFont(font)
def _drawText(self, painter: QPainter, text: str):
""" draw text """
painter.setFont(self.font())
painter.setPen(Qt.white if isDarkTheme() else Qt.black)
painter.drawText(self.rect(), Qt.AlignCenter, text)
def paintEvent(self, e):
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing)
cw = 6 # circle thickness
w = min(self.height(), self.width()) - cw
rc = QRectF(cw/2, self.height()/2 - w/2, w, w)
# draw background
bc = self.darkBackgroundColor if isDarkTheme() else self.lightBackgroundColor
pen = QPen(bc, cw, cap=Qt.RoundCap, join=Qt.RoundJoin)
painter.setPen(pen)
painter.drawArc(rc, 0, 360*16)
if self.maximum() <= self.minimum():
return
# draw bar
pen.setColor(themeColor())
painter.setPen(pen)
degree = int(self.val / (self.maximum() - self.minimum()) * 360)
painter.drawArc(rc, 90*16, -degree*16)
# draw text
if self.isTextVisible():
self._drawText(painter, self.valText())
......@@ -49,11 +49,10 @@ class TableItemDelegate(QStyledItemDelegate):
def updateEditorGeometry(self, editor: QWidget, option: QStyleOptionViewItem, index: QModelIndex):
rect = option.rect
h = super().sizeHint(option, index).height()
y = rect.y() + self.margin + (h - editor.height()) // 2
x, w = max(4, rect.x()), rect.width()
y = rect.y() + (rect.height() - editor.height()) // 2
x, w = max(8, rect.x()), rect.width()
if index.column() == 0:
w -= 4
w -= 8
editor.setGeometry(x, y, w, rect.height())
......@@ -153,6 +152,7 @@ class TableBase:
self.entered.connect(lambda i: self._setHoverRow(i.row()))
self.pressed.connect(lambda i: self._setPressedRow(i.row()))
self.verticalHeader().sectionClicked.connect(self.selectRow)
def showEvent(self, e):
QTableView.showEvent(self, e)
......
......@@ -3,10 +3,4 @@ PyQt5-Frameless-Window
darkdetect
colorthief
scipy
pillow
sphinx-markdown-tables==0.0.17
sphinx-intl
furo
sphinx-autoapi
sphinx-copybutton
sphinx_design
\ No newline at end of file
pillow
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册