35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
"""Shared two-column form layout for settings sections."""
|
|
|
|
from typing import TypeAlias
|
|
|
|
from PyQt6.QtWidgets import QFormLayout, QHBoxLayout, QWidget
|
|
|
|
FormLabel: TypeAlias = str | QWidget
|
|
FormRow: TypeAlias = QWidget | tuple[FormLabel, QWidget]
|
|
|
|
|
|
def build_two_column_form_widget(
|
|
parent: QWidget, rows: list[FormRow], *, split_index: int | None = None,
|
|
) -> QWidget:
|
|
panel = QWidget(parent)
|
|
layout = QHBoxLayout(panel)
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
|
layout.setSpacing(12)
|
|
split = (len(rows) + 1) // 2 if split_index is None else max(0, min(split_index, len(rows)))
|
|
for column_rows in (rows[:split], rows[split:]):
|
|
column = QWidget(panel)
|
|
form = QFormLayout(column)
|
|
form.setContentsMargins(0, 0, 0, 0)
|
|
form.setHorizontalSpacing(10)
|
|
form.setVerticalSpacing(6)
|
|
form.setRowWrapPolicy(QFormLayout.RowWrapPolicy.WrapLongRows)
|
|
form.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow)
|
|
for row in column_rows:
|
|
if isinstance(row, tuple):
|
|
label, widget = row
|
|
form.addRow(label, widget)
|
|
else:
|
|
form.addRow(row)
|
|
layout.addWidget(column, stretch=1)
|
|
return panel
|