dcs_liberation/qt_ui/widgets/QLabeledWidget.py
Dan Albert 4a7dae9cc2 Upgrade to PySide6.
PySide2 renamed to PySide6 for Qt 6 support. It doesn't seem like
PySide2 is getting a 3.10 wheel, so upgrade to Qt 6 to prep for that.
2021-11-20 19:26:18 -08:00

26 lines
785 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)