mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
27 lines
786 B
Python
27 lines
786 B
Python
"""A layout containing a widget with an associated label."""
|
|
|
|
from typing import Optional
|
|
|
|
from PySide6.QtCore import Qt
|
|
from PySide6.QtWidgets import QHBoxLayout, QLabel, QWidget
|
|
|
|
|
|
class QLabeledWidget(QHBoxLayout):
|
|
"""A layout containing a widget with an associated label.
|
|
|
|
Best used for vertical forms, where the given widget is the input and the
|
|
label is used to name the input.
|
|
"""
|
|
|
|
def __init__(
|
|
self, text: str, widget: QWidget, tooltip: Optional[str] = None
|
|
) -> None:
|
|
super().__init__()
|
|
label = QLabel(text)
|
|
self.addWidget(label)
|
|
self.addStretch()
|
|
self.addWidget(widget, alignment=Qt.AlignRight)
|
|
if tooltip is not None:
|
|
label.setToolTip(tooltip)
|
|
widget.setToolTip(tooltip)
|