first ui widget placement

This commit is contained in:
2025-09-06 17:46:17 +02:00
parent 1896d75c50
commit 69a31e153f
3 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
from PySide6.QtWidgets import QWidget, QLabel, QVBoxLayout
from PySide6.QtGui import QPalette, QColor
from PySide6.QtCore import Qt
class PlaceholderWidget(QWidget):
"""A custom widget to display a colored background with centered text."""
def __init__(self, text: str, color: str, parent=None):
super().__init__(parent)
self.setAutoFillBackground(True)
self.set_color(color)
self.label = QLabel(text)
self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
font = self.label.font()
font.setPointSize(24)
self.label.setFont(font)
self.label.setWordWrap(True)
layout = QVBoxLayout(self)
layout.addWidget(self.label)
self.setLayout(layout)
def set_text(self, text: str):
self.label.setText(text)
def set_color(self, color: str):
palette = self.palette()
palette.setColor(QPalette.ColorRole.Window, QColor(color))
self.setPalette(palette)
def set_text_color(self, color: str):
palette = self.label.palette()
palette.setColor(QPalette.ColorRole.WindowText, QColor(color))
self.label.setPalette(palette)