@@ -317,18 +317,33 @@ def add_label(widget, label, label_before=True, horizontal=True):
317317 return combine_blocks (label , widget , horizontal = horizontal )
318318
319319
320- def add_label (widget , label , label_before = True , horizontal = True ):
321- if label_before :
322- return combine_blocks (widget , label , horizontal = horizontal )
323- else :
324- return combine_blocks (label , widget , horizontal = horizontal )
320+ class ContainerWidget (QWidget ):
321+ def __init__ (
322+ self , l = 0 , t = 0 , r = 1 , b = 11 , vertical = True , parent = None , fixed = True
323+ ):
324+ """
325+ Creates a container widget that can contain other widgets
326+ Args:
327+ l: left margin in pixels
328+ t: top margin in pixels
329+ r: right margin in pixels
330+ b: bottom margin in pixels
331+ vertical: if True, renders vertically. Horizontal otherwise
332+ parent: parent QWidget
333+ fixed: uses QLayout.SetFixedSize if True
334+ """
325335
336+ super ().__init__ (parent )
337+ self .layout = None
326338
327- def add_label (widget , label , label_before = True , horizontal = True ):
328- if label_before :
329- return combine_blocks (widget , label , horizontal = horizontal )
330- else :
331- return combine_blocks (label , widget , horizontal = horizontal )
339+ if vertical :
340+ self .layout = QVBoxLayout (self )
341+ else :
342+ self .layout = QHBoxLayout (self )
343+
344+ self .layout .setContentsMargins (l , t , r , b )
345+ if fixed :
346+ self .layout .setSizeConstraint (QLayout .SetFixedSize )
332347
333348
334349class RadioButton (QRadioButton ):
@@ -1244,49 +1259,6 @@ def create_single_widget_group(
12441259 layout .addWidget (group )
12451260
12461261
1247-
1248- class GroupedWidget (QGroupBox ):
1249- """Subclass of QGroupBox designed to easily group widgets belonging to a same category"""
1250-
1251- def __init__ (self , title , l = 7 , t = 20 , r = 7 , b = 11 , parent = None ):
1252- super ().__init__ (title , parent )
1253-
1254- self .setSizePolicy (QSizePolicy .Fixed )
1255-
1256- self .layout = QVBoxLayout ()
1257- self .layout .setContentsMargins (l , t , r , b )
1258- self .layout .setSizeConstraint (QLayout .SetFixedSize )
1259-
1260- @property
1261- def layout (self ) -> "QLayout" :
1262- return self .layout
1263-
1264- @classmethod
1265- def create_single_widget_group (
1266- cls , title , widget , layout , l = 7 , t = 20 , r = 7 , b = 11
1267- ):
1268- group , group_layout = cls (title , l , t , r , b )
1269- group_layout .addWidget (widget )
1270- group .setLayout (group_layout )
1271- layout .addWidget (group )
1272-
1273-
1274- class ContainerWidget (QWidget ): # TODO convert calls
1275- def __init__ (self , l = 0 , t = 0 , r = 1 , b = 11 , vertical = True , parent = None ):
1276-
1277- super ().__init__ (parent )
1278- self .layout = None
1279-
1280- if vertical :
1281- self .layout = QVBoxLayout (self )
1282- else :
1283- self .layout = QHBoxLayout (self )
1284-
1285- self .layout .setContentsMargins (l , t , r , b )
1286- if fixed :
1287- self .layout .setSizeConstraint (QLayout .SetFixedSize )
1288-
1289-
12901262def add_widgets (layout , widgets , alignment = LEFT_AL ):
12911263 """Adds all widgets in the list to layout, with the specified alignment.
12921264 If alignment is None, no alignment is set.
0 commit comments