47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
from PySide6.QtWidgets import QWidget, QLabel, QVBoxLayout, QHBoxLayout, QSizePolicy
|
|
from PySide6.QtCore import Qt
|
|
|
|
class Card(QWidget):
|
|
"""Premium card tile for dashboard."""
|
|
def __init__(self, title: str, value: str, sub: str, icon_text: str = "◻"):
|
|
super().__init__()
|
|
self.setObjectName("Card")
|
|
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
|
|
|
root = QVBoxLayout(self)
|
|
root.setContentsMargins(18, 16, 18, 16)
|
|
root.setSpacing(10)
|
|
|
|
top = QHBoxLayout()
|
|
top.setSpacing(10)
|
|
|
|
lbl_title = QLabel(title)
|
|
lbl_title.setObjectName("CardTitle")
|
|
|
|
icon = QLabel(icon_text)
|
|
icon.setAlignment(Qt.AlignCenter)
|
|
icon.setFixedSize(44, 44)
|
|
icon.setStyleSheet("background: rgba(58,134,255,0.12); border-radius: 14px;")
|
|
|
|
top.addWidget(lbl_title, 1, Qt.AlignLeft | Qt.AlignVCenter)
|
|
top.addWidget(icon, 0, Qt.AlignRight | Qt.AlignVCenter)
|
|
|
|
lbl_value = QLabel(value)
|
|
lbl_value.setObjectName("CardValue")
|
|
|
|
lbl_sub = QLabel(sub)
|
|
lbl_sub.setObjectName("CardSub")
|
|
|
|
root.addLayout(top)
|
|
root.addStretch(1)
|
|
root.addWidget(lbl_value)
|
|
root.addWidget(lbl_sub)
|
|
|
|
# clickable feel
|
|
self.setCursor(Qt.PointingHandCursor)
|
|
|
|
def mousePressEvent(self, event):
|
|
# заглушка клика по карточке
|
|
print(f"[Card] Click: {self.objectName()}")
|
|
super().mousePressEvent(event)
|