Skip to content

DialogButtonBox

Qt Base Class: QDialogButtonBox

Signature: QDialogButtonBox(self, buttons: PySide6.QtWidgets.QDialogButtonBox.StandardButton, orientation: PySide6.QtCore.Qt.Orientation, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None QDialogButtonBox(self, buttons: PySide6.QtWidgets.QDialogButtonBox.StandardButton, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None QDialogButtonBox(self, orientation: PySide6.QtCore.Qt.Orientation, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None QDialogButtonBox(self, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None

Base classes

Name Children Inherits
WidgetMixin
prettyqt.widgets.widget
QDialogButtonBox
PySide6.QtWidgets
QDialogButtonBox(self, buttons: PySide6.QtWidgets.QDialogButtonBox.StandardButton, orientation: PySide6.QtCore.Qt.Orientation, parent: Optional[PySide6.QtWidgets.QWidget] \= None) -> None

⋔ Inheritance diagram

graph TD
  1473296194400["widgets.DialogButtonBox"]
  1473293688240["widgets.WidgetMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473245548480["gui.PaintDeviceMixin"]
  1473241470608["QtWidgets.QDialogButtonBox"]
  1473290849680["QtWidgets.QWidget"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473300082368["QtGui.QPaintDevice"]
  1473293688240 --> 1473296194400
  1473299815024 --> 1473293688240
  140713234304496 --> 1473299815024
  1473245548480 --> 1473293688240
  140713234304496 --> 1473245548480
  1473241470608 --> 1473296194400
  1473290849680 --> 1473241470608
  1473288842240 --> 1473290849680
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208
  1473300082368 --> 1473290849680
  1473291690208 --> 1473300082368

🛈 DocStrings

Bases: WidgetMixin, QDialogButtonBox

Widget presenting buttons in a layout that is appropriate to the widget style.

Source code in prettyqt\widgets\dialogbuttonbox.py
class DialogButtonBox(widgets.WidgetMixin, widgets.QDialogButtonBox):
    """Widget presenting buttons in a layout that is appropriate to the widget style."""

    button_clicked = core.Signal(str)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.clicked.connect(self.on_click)

    def __len__(self) -> int:
        return len(self.buttons())

    def __getitem__(self, index: StandardButtonStr) -> widgets.QPushButton:
        return self.button(STANDARD_BUTTON[index])

    def __iter__(self) -> Iterator[widgets.QAbstractButton]:
        return iter(self.buttons())

    def __contains__(self, index: StandardButtonStr):
        return self.button(STANDARD_BUTTON[index]) is not None

    def _get_map(self):
        maps = super()._get_map()
        maps |= {
            "orientation": constants.ORIENTATION,
            "standardButtons": STANDARD_BUTTON,
        }
        return maps

    @classmethod
    def create(cls, **kwargs) -> Self:
        box = cls()
        for k, v in kwargs.items():
            box.add_default_button(k, callback=v)  # type: ignore
        return box

    def on_click(self, button: core.QObject):
        self.button_clicked.emit(button.objectName())

    def set_horizontal(self):
        self.setOrientation(constants.HORIZONTAL)

    def set_vertical(self):
        self.setOrientation(constants.VERTICAL)

    def set_orientation(
        self, orientation: constants.OrientationStr | constants.Orientation
    ):
        """Set the orientation of the button box.

        Args:
            orientation: orientation for the button box
        """
        self.setOrientation(constants.ORIENTATION.get_enum_value(orientation))

    def get_orientation(self) -> constants.OrientationStr:
        """Return current orientation.

        Returns:
            orientation
        """
        return constants.ORIENTATION.inverse[self.orientation()]

    def add_default_buttons(
        self, buttons: Sequence[StandardButtonStr]
    ) -> listdelegators.ListDelegator[widgets.QPushButton]:
        return [self.add_default_button(btn) for btn in buttons]

    def add_default_button(
        self,
        button: StandardButtonStr | widgets.QDialogButtonBox.StandardButton,
        callback: Callable | None = None,
    ) -> widgets.QPushButton:
        """Add a default button.

        Args:
            button: button to add
            callback: function to call when button gets clicked

        Returns:
            created button
        """
        btn = super().addButton(STANDARD_BUTTON.get_enum_value(button))
        btn.setObjectName(button)
        if callback:
            btn.clicked.connect(callback)
        return btn

    def add_button(
        self,
        button: widgets.QPushButton | str,
        role: RoleStr | widgets.QDialogButtonBox.ButtonRole = "accept",
        callback: Callable | None = None,
    ) -> widgets.QPushButton:
        """Add a button.

        Args:
            button: button to add
            role: role of the button
            callback: function to call when button gets clicked

        Returns:
            created button
        """
        if isinstance(button, str):
            button = widgets.PushButton(button)
        self.addButton(button, ROLES.get_enum_value(role))
        if callback:
            button.clicked.connect(callback)
        return button

add_button(button: widgets.QPushButton | str, role: RoleStr | widgets.QDialogButtonBox.ButtonRole = 'accept', callback: Callable | None = None) -> widgets.QPushButton

Add a button.

Parameters:

Name Type Description Default
button QPushButton | str

button to add

required
role RoleStr | ButtonRole

role of the button

'accept'
callback Callable | None

function to call when button gets clicked

None
Source code in prettyqt\widgets\dialogbuttonbox.py
def add_button(
    self,
    button: widgets.QPushButton | str,
    role: RoleStr | widgets.QDialogButtonBox.ButtonRole = "accept",
    callback: Callable | None = None,
) -> widgets.QPushButton:
    """Add a button.

    Args:
        button: button to add
        role: role of the button
        callback: function to call when button gets clicked

    Returns:
        created button
    """
    if isinstance(button, str):
        button = widgets.PushButton(button)
    self.addButton(button, ROLES.get_enum_value(role))
    if callback:
        button.clicked.connect(callback)
    return button

add_default_button(button: StandardButtonStr | widgets.QDialogButtonBox.StandardButton, callback: Callable | None = None) -> widgets.QPushButton

Add a default button.

Parameters:

Name Type Description Default
button StandardButtonStr | StandardButton

button to add

required
callback Callable | None

function to call when button gets clicked

None
Source code in prettyqt\widgets\dialogbuttonbox.py
def add_default_button(
    self,
    button: StandardButtonStr | widgets.QDialogButtonBox.StandardButton,
    callback: Callable | None = None,
) -> widgets.QPushButton:
    """Add a default button.

    Args:
        button: button to add
        callback: function to call when button gets clicked

    Returns:
        created button
    """
    btn = super().addButton(STANDARD_BUTTON.get_enum_value(button))
    btn.setObjectName(button)
    if callback:
        btn.clicked.connect(callback)
    return btn

get_orientation() -> constants.OrientationStr

Return current orientation.

Source code in prettyqt\widgets\dialogbuttonbox.py
def get_orientation(self) -> constants.OrientationStr:
    """Return current orientation.

    Returns:
        orientation
    """
    return constants.ORIENTATION.inverse[self.orientation()]

set_orientation(orientation: constants.OrientationStr | constants.Orientation)

Set the orientation of the button box.

Parameters:

Name Type Description Default
orientation OrientationStr | Orientation

orientation for the button box

required
Source code in prettyqt\widgets\dialogbuttonbox.py
def set_orientation(
    self, orientation: constants.OrientationStr | constants.Orientation
):
    """Set the orientation of the button box.

    Args:
        orientation: orientation for the button box
    """
    self.setOrientation(constants.ORIENTATION.get_enum_value(orientation))

⌗ Property table

Qt Property Type Doc
objectName QString
modal bool
windowModality Qt::WindowModality
enabled bool
geometry QRect
frameGeometry QRect
normalGeometry QRect
x int
y int
pos QPoint
frameSize QSize
size QSize
width int
height int
rect QRect
childrenRect QRect
childrenRegion QRegion
sizePolicy QSizePolicy
minimumSize QSize
maximumSize QSize
minimumWidth int
minimumHeight int
maximumWidth int
maximumHeight int
sizeIncrement QSize
baseSize QSize
palette QPalette
font QFont
cursor QCursor
mouseTracking bool
tabletTracking bool
isActiveWindow bool
focusPolicy Qt::FocusPolicy
focus bool
contextMenuPolicy Qt::ContextMenuPolicy
updatesEnabled bool
visible bool
minimized bool
maximized bool
fullScreen bool
sizeHint QSize
minimumSizeHint QSize
acceptDrops bool
windowTitle QString
windowIcon QIcon
windowIconText QString
windowOpacity double
windowModified bool
toolTip QString
toolTipDuration int
statusTip QString
whatsThis QString
accessibleName QString
accessibleDescription QString
layoutDirection Qt::LayoutDirection
autoFillBackground bool
styleSheet QString
locale QLocale
windowFilePath QString
inputMethodHints QFlags
orientation Qt::Orientation
standardButtons QFlags
centerButtons bool