"""A tile-styled card with a title row and a dynamic list of label:value rows underneath - the one component nearly every new "useful vs. less useful" section is built from (weather, attached implement, missions, storage, husbandry, prices, players, session settings, ...).""" from __future__ import annotations from PySide6.QtWidgets import QFrame, QHBoxLayout, QLabel, QVBoxLayout, QWidget from widgets.common import clear_layout, style_role class InfoCard(QFrame): def __init__(self, icon: str, title: str, parent=None) -> None: super().__init__(parent) self.setProperty("role", "tile") outer = QVBoxLayout(self) outer.setContentsMargins(14, 10, 14, 10) outer.setSpacing(6) head = QHBoxLayout() head.setSpacing(8) icon_label = QLabel(icon) icon_label.setStyleSheet("font-size: 15px;") head.addWidget(icon_label) title_label = QLabel(title) style_role(title_label, "section-title") head.addWidget(title_label) head.addStretch(1) outer.addLayout(head) self.rows_layout = QVBoxLayout() self.rows_layout.setSpacing(3) outer.addLayout(self.rows_layout) def set_rows(self, rows: list[tuple[str, str]], empty_text: str = "Keine Daten") -> None: clear_layout(self.rows_layout) if not rows: lbl = QLabel(empty_text) style_role(lbl, "dim") self.rows_layout.addWidget(lbl) return for name, value in rows: row = QWidget() row_layout = QHBoxLayout(row) row_layout.setContentsMargins(0, 0, 0, 0) name_lbl = QLabel(name) style_role(name_lbl, "dim") row_layout.addWidget(name_lbl) row_layout.addStretch(1) value_lbl = QLabel(value) style_role(value_lbl, "row-value") row_layout.addWidget(value_lbl) self.rows_layout.addWidget(row)