Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70777b1

Browse files
committed
Improve margins in formlayout
1 parent 2698288 commit 70777b1

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

lib/matplotlib/backends/qt_editor/formlayout.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,30 @@ def is_edit_valid(edit):
209209
class FormWidget(QtWidgets.QWidget):
210210
update_buttons = QtCore.Signal()
211211

212-
def __init__(self, data, comment="", parent=None):
212+
def __init__(self, data, comment="", with_margin=False, parent=None):
213+
"""
214+
215+
Parameters
216+
----------
217+
data : list of (label, value) pairs
218+
The data to be edited in the form.
219+
comment : str
220+
221+
no_margin : bool, optional, default: False
222+
By default, the FormWidget has a margin around the form elements.
223+
This correct if the widget is a single element within another
224+
widget, e.g. a tab. However, if the FormWidget is part of a layout
225+
with
226+
is correct if the F
227+
parent : QWidget or None
228+
The parent widget.
229+
"""
213230
QtWidgets.QWidget.__init__(self, parent)
214231
self.data = copy.deepcopy(data)
215232
self.widgets = []
216233
self.formlayout = QtWidgets.QFormLayout(self)
234+
if not with_margin:
235+
self.formlayout.setContentsMargins(0, 0, 0, 0)
217236
if comment:
218237
self.formlayout.addRow(QtWidgets.QLabel(comment))
219238
self.formlayout.addRow(QtWidgets.QLabel(" "))
@@ -370,13 +389,14 @@ def __init__(self, datalist, comment="", parent=None):
370389
layout = QtWidgets.QVBoxLayout()
371390
self.tabwidget = QtWidgets.QTabWidget()
372391
layout.addWidget(self.tabwidget)
392+
layout.setContentsMargins(0, 0, 0, 0)
373393
self.setLayout(layout)
374394
self.widgetlist = []
375395
for data, title, comment in datalist:
376396
if len(data[0]) == 3:
377397
widget = FormComboWidget(data, comment=comment, parent=self)
378398
else:
379-
widget = FormWidget(data, comment=comment, parent=self)
399+
widget = FormWidget(data, with_margin=True, comment=comment)
380400
index = self.tabwidget.addTab(widget, title)
381401
self.tabwidget.setTabToolTip(index, comment)
382402
self.widgetlist.append(widget)
@@ -405,8 +425,7 @@ def __init__(self, data, title="", comment="",
405425
self.formwidget = FormComboWidget(data, comment=comment,
406426
parent=self)
407427
else:
408-
self.formwidget = FormWidget(data, comment=comment,
409-
parent=self)
428+
self.formwidget = FormWidget(data, comment=comment, parent=self)
410429
layout = QtWidgets.QVBoxLayout()
411430
layout.addWidget(self.formwidget)
412431

0 commit comments

Comments
 (0)