From a6ff68bf51210ef85f3c74ae6aef00bd28b634e4 Mon Sep 17 00:00:00 2001 From: phil65 Date: Sun, 14 May 2023 09:59:57 +0200 Subject: [PATCH] feat(GroupBox): add get_alignment method --- prettyqt/widgets/groupbox.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/prettyqt/widgets/groupbox.py b/prettyqt/widgets/groupbox.py index f0cc33c1d..e5f2c9491 100644 --- a/prettyqt/widgets/groupbox.py +++ b/prettyqt/widgets/groupbox.py @@ -2,7 +2,7 @@ from prettyqt import constants, widgets from prettyqt.qt import QtWidgets -from prettyqt.utils import get_repr +from prettyqt.utils import InvalidParamError, get_repr class GroupBox(widgets.WidgetMixin, QtWidgets.QGroupBox): @@ -28,9 +28,27 @@ def __repr__(self): def set_title(self, title: str): self.setTitle(title) - def set_alignment(self, alignment): + def set_alignment(self, alignment: constants.HorizontalAlignmentStr): + """Set the title alignment of the groupbox. + + Args: + alignment: title alignment for the groupbox + + Raises: + InvalidParamError: alignment does not exist + """ + if alignment not in constants.H_ALIGNMENT: + raise InvalidParamError(alignment, constants.ALIGNMENTS) self.setAlignment(constants.H_ALIGNMENT[alignment]) + def get_alignment(self) -> constants.HorizontalAlignmentStr: + """Return current title alignment. + + Returns: + title alignment + """ + return constants.H_ALIGNMENT.inverse[self.alignment()] + def set_enabled(self, state): for widget in self.layout(): widget.setEnabled(state) @@ -39,7 +57,7 @@ def set_enabled(self, state): if __name__ == "__main__": app = widgets.app() widget = GroupBox() - ly = widgets.BoxLayout() + ly = widgets.HBoxLayout() ly += widgets.RadioButton("test") widget.set_layout(ly) widget.show()