@@ -209,11 +209,30 @@ def is_edit_valid(edit):
209
209
class FormWidget (QtWidgets .QWidget ):
210
210
update_buttons = QtCore .Signal ()
211
211
212
- def __init__ (self , data , comment = "" , parent = None ):
212
+ def __init__ (self , data , comment = "" , with_margin = False , parent = None ):
213
+ """
214
+ Parameters
215
+ ----------
216
+ data : list of (label, value) pairs
217
+ The data to be edited in the form.
218
+ comment : str, optional
219
+
220
+ with_margin : bool, optional, default: False
221
+ If False, the form elements reach to the border of the widget.
222
+ This is the desired behavior if the FormWidget is used as a widget
223
+ alongside with other widgets such as a QComboBox, which also do
224
+ not have a margin around them.
225
+ However, a margin can be desired if the FormWidget is the only
226
+ widget within a container, e.g. a tab in a QTabWidget.
227
+ parent : QWidget or None
228
+ The parent widget.
229
+ """
213
230
QtWidgets .QWidget .__init__ (self , parent )
214
231
self .data = copy .deepcopy (data )
215
232
self .widgets = []
216
233
self .formlayout = QtWidgets .QFormLayout (self )
234
+ if not with_margin :
235
+ self .formlayout .setContentsMargins (0 , 0 , 0 , 0 )
217
236
if comment :
218
237
self .formlayout .addRow (QtWidgets .QLabel (comment ))
219
238
self .formlayout .addRow (QtWidgets .QLabel (" " ))
@@ -370,13 +389,15 @@ def __init__(self, datalist, comment="", parent=None):
370
389
layout = QtWidgets .QVBoxLayout ()
371
390
self .tabwidget = QtWidgets .QTabWidget ()
372
391
layout .addWidget (self .tabwidget )
392
+ layout .setContentsMargins (0 , 0 , 0 , 0 )
373
393
self .setLayout (layout )
374
394
self .widgetlist = []
375
395
for data , title , comment in datalist :
376
396
if len (data [0 ]) == 3 :
377
397
widget = FormComboWidget (data , comment = comment , parent = self )
378
398
else :
379
- widget = FormWidget (data , comment = comment , parent = self )
399
+ widget = FormWidget (data , with_margin = True , comment = comment ,
400
+ parent = self )
380
401
index = self .tabwidget .addTab (widget , title )
381
402
self .tabwidget .setTabToolTip (index , comment )
382
403
self .widgetlist .append (widget )
0 commit comments