dcs_liberation/qt_ui/widgets/QLabeledWidget.py
Dan Albert 306971230b Update to PySide6.
It sounds like PySide2 will not be moving to Python 3.11, so we're stuck
on 3.10 without this. Upgrading to a newer Qt also fixes some high DPI
bugs (the file browser dialog for save/load is no longer tiny on 4k).

https://github.com/pyinstaller/pyinstaller/issues/5414 previously
blocked this, but the bug appears to be fixed now.
2022-12-29 16:26:50 -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)