Skip to content

Commit a380e06

Browse files
committed
Handled deprecated QWidget.getContentsMargins
1 parent eb630b5 commit a380e06

7 files changed

Lines changed: 41 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# PythonQwt Releases
22

3+
## Version 0.10.6
4+
5+
- Handled all occurences of deprecated ``QWidget.getContentsMargins`` method.
6+
37
## Version 0.10.5
48

59
- [Issue #81](https://github.com/PlotPyStack/PythonQwt/issues/81) - Signal disconnection issue with PySide 6.5.3

qwt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
.. _GitHub: https://github.com/PlotPyStack/PythonQwt
2828
"""
2929

30-
__version__ = "0.10.5"
30+
__version__ = "0.10.6"
3131
QWT_VERSION_STR = "6.1.5"
3232

3333
import warnings

qwt/dyngrid_layout.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,11 @@ def stretchGrid(self, rect, numColumns, rowHeight, colWidth):
299299
return
300300
expandH = self.expandingDirections() & Qt.Horizontal
301301
expandV = self.expandingDirections() & Qt.Vertical
302-
mleft, mtop, mright, mbottom = self.getContentsMargins()
302+
margins = self.contentsMargins()
303+
wmargins = margins.left() + margins.right()
304+
hmargins = margins.top() + margins.bottom()
303305
if expandH:
304-
xDelta = rect.width() - (mleft + mright) - (numColumns - 1) * self.spacing()
306+
xDelta = rect.width() - wmargins - (numColumns - 1) * self.spacing()
305307
for col in range(numColumns):
306308
xDelta -= colWidth[col]
307309
if xDelta > 0:
@@ -313,7 +315,7 @@ def stretchGrid(self, rect, numColumns, rowHeight, colWidth):
313315
numRows = self.itemCount() / numColumns
314316
if self.itemCount() % numColumns:
315317
numRows += 1
316-
yDelta = rect.height() - (mtop + mbottom) - (numRows - 1) * self.spacing()
318+
yDelta = rect.height() - hmargins - (numRows - 1) * self.spacing()
317319
for row in range(numRows):
318320
yDelta -= rowHeight[row]
319321
if yDelta > 0:

qwt/legend.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ def setSpacing(self, spacing):
308308
spacing = max([spacing, 0])
309309
if spacing != self.__data.spacing:
310310
self.__data.spacing = spacing
311-
margin = max(self.getContentsMargins())
311+
mgn = self.contentsMargins()
312+
margin = max([mgn.left(), mgn.top(), mgn.right(), mgn.bottom()])
312313
indent = margin + self.__data.spacing
313314
if self.__data.icon.width() > 0:
314315
indent += self.__data.icon.width() + self.__data.spacing
@@ -912,12 +913,12 @@ def renderLegend(self, painter, rect, fillBackground):
912913
legendLayout = self.__data.view.contentsWidget.layout()
913914
if legendLayout is None:
914915
return
915-
left, right, top, bottom = self.layout().getContentsMargins()
916+
margins = self.layout().contentsMargins()
916917
layoutRect = QRect()
917-
layoutRect.setLeft(math.ceil(rect.left()) + left)
918-
layoutRect.setTop(math.ceil(rect.top()) + top)
919-
layoutRect.setRight(math.ceil(rect.right()) - right)
920-
layoutRect.setBottom(math.ceil(rect.bottom()) - bottom)
918+
layoutRect.setLeft(math.ceil(rect.left()) + margins.left())
919+
layoutRect.setTop(math.ceil(rect.top()) + margins.top())
920+
layoutRect.setRight(math.ceil(rect.right()) - margins.right())
921+
layoutRect.setBottom(math.ceil(rect.bottom()) - margins.bottom())
921922
numCols = legendLayout.columnsForWidth(layoutRect.width())
922923
itemRects = legendLayout.layoutItems(layoutRect, numCols)
923924
index = 0
@@ -949,7 +950,8 @@ def renderItem(self, painter, widget, rect, fillBackground):
949950
if label is not None:
950951
icon = label.data().icon()
951952
sz = icon.defaultSize()
952-
margin = max(label.getContentsMargins())
953+
mgn = label.contentsMargins()
954+
margin = max([mgn.left(), mgn.top(), mgn.right(), mgn.bottom()])
953955
iconRect = QRectF(
954956
rect.x() + margin,
955957
rect.center().y() - 0.5 * sz.height(),

qwt/plot_layout.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ def init(self, plot, rect):
135135
self.scale[axis].dimWithoutTitle = 0
136136
layout = plot.canvas().layout()
137137
if layout is not None:
138-
self.canvas.contentsMargins = layout.getContentsMargins()
138+
mgn = layout.contentsMargins()
139+
self.canvas.contentsMargins = [
140+
mgn.left(), mgn.top(), mgn.right(), mgn.bottom()
141+
]
139142

140143

141144
class QwtPlotLayout_PrivateData(object):
@@ -571,7 +574,10 @@ def __init__(self):
571574
if layout is None:
572575
left, top, right, bottom = 0, 0, 0, 0
573576
else:
574-
left, top, right, bottom = layout.getContentsMargins()
577+
mgn = layout.contentsMargins()
578+
left, top, right, bottom = (
579+
mgn.left(), mgn.top(), mgn.right(), mgn.bottom()
580+
)
575581
for axis in QwtPlot.AXES:
576582
if plot.axisEnabled(axis):
577583
scl = plot.axisWidget(axis)

qwt/plot_renderer.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ def render(self, plot, painter, plotRect):
356356
invtrans, _ok = transform.inverted()
357357
layoutRect = invtrans.mapRect(plotRect)
358358
if not (self.__data.discardFlags & self.DiscardBackground):
359-
left, top, right, bottom = plot.getContentsMargins()
360-
layoutRect.adjust(left, top, -right, -bottom)
359+
mg = plot.contentsMargins()
360+
layoutRect.adjust(mg.left(), mg.top(), -mg.right(), -mg.bottom())
361361

362362
layout = plot.plotLayout()
363363
baseLineDists = canvasMargins = [None] * len(QwtPlot.AXES)
@@ -367,7 +367,10 @@ def render(self, plot, painter, plotRect):
367367
if self.__data.layoutFlags & self.FrameWithScales:
368368
scaleWidget = plot.axisWidget(axisId)
369369
if scaleWidget:
370-
baseLineDists[axisId] = max(scaleWidget.getContentsMargins())
370+
mgn = scaleWidget.contentsMargins()
371+
baseLineDists[axisId] = max([
372+
mgn.left(), mgn.top(), mgn.right(), mgn.bottom()
373+
])
371374
scaleWidget.setMargin(0)
372375
if not plot.axisEnabled(axisId):
373376
# When we have a scale the frame is painted on
@@ -430,7 +433,10 @@ def render(self, plot, painter, plotRect):
430433
for axisId in QwtPlot.AXES:
431434
scaleWidget = plot.axisWidget(axisId)
432435
if scaleWidget:
433-
baseDist = max(scaleWidget.getContentsMargins())
436+
mgn = scaleWidget.contentsMargins()
437+
baseDist = max([
438+
mgn.left(), mgn.top(), mgn.right(), mgn.bottom()
439+
])
434440
startDist, endDist = scaleWidget.getBorderDistHint()
435441
self.renderScale(
436442
plot,

qwt/scale_widget.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,10 @@ def minimumSizeHint(self):
637637
if self.layout() is None:
638638
left, top, right, bottom = 0, 0, 0, 0
639639
else:
640-
left, top, right, bottom = self.layout().getContentsMargins()
640+
mgn = self.layout().contentsMargins()
641+
left, top, right, bottom = (
642+
mgn.left(), mgn.top(), mgn.right(), mgn.bottom()
643+
)
641644
return size + QSize(left + right, top + bottom)
642645

643646
def titleHeightForWidth(self, width):

0 commit comments

Comments
 (0)