Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit8a8924c

Browse files
committed
Initial HiDPI support for qt5agg backend
1 parent390dab3 commit8a8924c

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

‎lib/matplotlib/backends/backend_qt5.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,13 @@ def leaveEvent(self, event):
249249
QtWidgets.QApplication.restoreOverrideCursor()
250250
FigureCanvasBase.leave_notify_event(self,guiEvent=event)
251251

252+
defmouseEventCoords(self,pos):
253+
x,y=self.mouseEventCoords(pos)
254+
print(x,y)
255+
returnx,y
256+
252257
defmousePressEvent(self,event):
253-
x=event.pos().x()
254-
# flipy so y=0 is bottom of canvas
255-
y=self.figure.bbox.height-event.pos().y()
258+
x,y=self.mouseEventCoords(event.pos())
256259
button=self.buttond.get(event.button())
257260
ifbuttonisnotNone:
258261
FigureCanvasBase.button_press_event(self,x,y,button,
@@ -261,9 +264,7 @@ def mousePressEvent(self, event):
261264
print('button pressed:',event.button())
262265

263266
defmouseDoubleClickEvent(self,event):
264-
x=event.pos().x()
265-
# flipy so y=0 is bottom of canvas
266-
y=self.figure.bbox.height-event.pos().y()
267+
x,y=self.mouseEventCoords(event.pos())
267268
button=self.buttond.get(event.button())
268269
ifbuttonisnotNone:
269270
FigureCanvasBase.button_press_event(self,x,y,
@@ -273,16 +274,12 @@ def mouseDoubleClickEvent(self, event):
273274
print('button doubleclicked:',event.button())
274275

275276
defmouseMoveEvent(self,event):
276-
x=event.x()
277-
# flipy so y=0 is bottom of canvas
278-
y=self.figure.bbox.height-event.y()
277+
x,y=self.mouseEventCoords(event)
279278
FigureCanvasBase.motion_notify_event(self,x,y,guiEvent=event)
280279
# if DEBUG: print('mouse move')
281280

282281
defmouseReleaseEvent(self,event):
283-
x=event.x()
284-
# flipy so y=0 is bottom of canvas
285-
y=self.figure.bbox.height-event.y()
282+
x,y=self.mouseEventCoords(event)
286283
button=self.buttond.get(event.button())
287284
ifbuttonisnotNone:
288285
FigureCanvasBase.button_release_event(self,x,y,button,
@@ -291,9 +288,7 @@ def mouseReleaseEvent(self, event):
291288
print('button released')
292289

293290
defwheelEvent(self,event):
294-
x=event.x()
295-
# flipy so y=0 is bottom of canvas
296-
y=self.figure.bbox.height-event.y()
291+
x,y=self.mouseEventCoords(event)
297292
# from QWheelEvent::delta doc
298293
ifevent.pixelDelta().x()==0andevent.pixelDelta().y()==0:
299294
steps=event.angleDelta().y()/120

‎lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def paintEvent(self, e):
100100
qImage=QtGui.QImage(stringBuffer,self.renderer.width,
101101
self.renderer.height,
102102
QtGui.QImage.Format_ARGB32)
103+
qImage.setDevicePixelRatio(self._dpi_ratio)
103104
# get the rectangle for the image
104105
rect=qImage.rect()
105106
p=QtGui.QPainter(self)
@@ -135,6 +136,7 @@ def paintEvent(self, e):
135136
stringBuffer=reg.to_string_argb()
136137
qImage=QtGui.QImage(stringBuffer,w,h,
137138
QtGui.QImage.Format_ARGB32)
139+
qImage.setDevicePixelRatio(self._dpi_ratio)
138140
# Adjust the stringBuffer reference count to work
139141
# around a memory leak bug in QImage() under PySide on
140142
# Python 3.x
@@ -222,6 +224,7 @@ def __init__(self, figure):
222224
super(FigureCanvasQTAgg,self).__init__(figure=figure)
223225
self._drawRect=None
224226
self.blitbox= []
227+
self._dpi_ratio=self.devicePixelRatio()
225228
self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)
226229

227230

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp