Skip to content

Commit

Permalink
feat(GroupBox): add get_alignment method
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed May 14, 2023
1 parent 02e2aa9 commit a6ff68b
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions prettyqt/widgets/groupbox.py
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit a6ff68b

Please sign in to comment.