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

Skip to content

Commit c1ca736

Browse files
committed
Scale Qt5 rubberband by DPI ratio.
1 parent f599034 commit c1ca736

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ def __init__(self, figure):
6767
self._agg_draw_pending = False
6868

6969
def drawRectangle(self, rect):
70-
self._drawRect = rect
70+
if rect is not None:
71+
self._drawRect = [pt / self._dpi_ratio for pt in rect]
72+
else:
73+
self._drawRect = None
7174
self.update()
7275

7376
def paintEvent(self, e):
@@ -112,7 +115,9 @@ def paintEvent(self, e):
112115

113116
# draw the zoom rectangle to the QPainter
114117
if self._drawRect is not None:
115-
p.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.DotLine))
118+
pen = QtGui.QPen(QtCore.Qt.black, 1 / self._dpi_ratio,
119+
QtCore.Qt.DotLine)
120+
p.setPen(pen)
116121
x, y, w, h = self._drawRect
117122
p.drawRect(x, y, w, h)
118123
p.end()
@@ -149,7 +154,9 @@ def paintEvent(self, e):
149154

150155
# draw the zoom rectangle to the QPainter
151156
if self._drawRect is not None:
152-
p.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.DotLine))
157+
pen = QtGui.QPen(QtCore.Qt.black, 1 / self._dpi_ratio,
158+
QtCore.Qt.DotLine)
159+
p.setPen(pen)
153160
x, y, w, h = self._drawRect
154161
p.drawRect(x, y, w, h)
155162

0 commit comments

Comments
 (0)