Alto
dev

alto.ui.answer_bank

A responsive, scrollable grid for large banks of answer buttons.

Examples

>>> AnswerBank().maximumHeight()
240

AnswerBank

AnswerBank(parent: QWidget | None = None)

Bases: QScrollArea

Wrap existing answer buttons to fit the available width and scroll long lists.

Attributes

  • buttons (list of QAbstractButton): The answer buttons in their display and keyboard navigation order.
  • content (QWidget): The grid’s content widget.

Examples

>>> bank = AnswerBank()
>>> bank.buttons
[]

Constructor

Create a bank that shows at most four rows before scrolling.

Parameters

  • parent (QWidget or None, default None): The widget that owns the bank.

Constructor examples

>>> AnswerBank().horizontalScrollBarPolicy() == Qt.ScrollBarPolicy.ScrollBarAlwaysOff
True

AnswerBank.set_buttons

def set_buttons(
    buttons: list[QAbstractButton],
    *,
    positions: list[tuple[int, int]] | None = None,
) -> None

Display answer buttons in a stable order.

Parameters

  • buttons (list of QAbstractButton): The buttons to arrange. Their caller owns answer handling.
  • positions (list of tuple of (int, int) or None): Optional row and column for each button. Each row wraps independently when space is limited.

Examples

>>> from PySide6.QtWidgets import QPushButton
>>> bank = AnswerBank()
>>> bank.set_buttons([QPushButton("m3"), QPushButton("P5")])
>>> len(bank.buttons)
2

AnswerBank.resizeEvent

def resizeEvent(event: QResizeEvent) -> None

Rewrap the buttons when the exercise or settings pane changes width.

Parameters

  • event (QResizeEvent): The resize notification.

Examples

>>> bank = AnswerBank()
>>> bank.resize(300, 200)
>>> bank.width()
300