Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4c35cf4

Browse filesBrowse files
committed
Improve margins in formlayout
1 parent f093129 commit 4c35cf4
Copy full SHA for 4c35cf4

File tree

Expand file treeCollapse file tree

1 file changed

+23
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-2
lines changed

‎lib/matplotlib/backends/qt_editor/_formlayout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_editor/_formlayout.py
+23-2Lines changed: 23 additions & 2 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+
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+
"""
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,15 @@ 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,
400+
parent=self)
380401
index = self.tabwidget.addTab(widget, title)
381402
self.tabwidget.setTabToolTip(index, comment)
382403
self.widgetlist.append(widget)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.