Files
leonpan-pc/app/view/components/gb_information_card.py
2025-10-29 22:20:21 +08:00

38 lines
1.2 KiB
Python

# coding: utf-8
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QVBoxLayout
from qfluentwidgets import BodyLabel, ElevatedCardWidget, SubtitleLabel
class GbInformationCard(ElevatedCardWidget):
def __init__(self, amount,station,parent=None):
super().__init__(parent=parent)
self.currentAmountLabel = SubtitleLabel(self)
self.currentAmountLabel.setText(self.formatSize(amount))
self.currentAmountLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.stationLabel = BodyLabel(station,self)
self.stationLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.vBoxLayout = QVBoxLayout(self)
self.vBoxLayout.setContentsMargins(2,5,2,5)
self.vBoxLayout.addWidget(self.currentAmountLabel,0,Qt.AlignmentFlag.AlignTop)
self.vBoxLayout.addSpacing(0)
self.vBoxLayout.addWidget(self.stationLabel,0,Qt.AlignmentFlag.AlignTop)
@staticmethod
def formatSize(size):
"""格式化文件大小"""
for unit in ["B", "KB", "MB", "GB", "TB"]:
if size < 1024:
return f"{size:.2f} {unit}"
size /= 1024
return f"{size:.2f} PB"
def updateValue(self,value):
self.currentAmountLabel.setText(self.formatSize(value))