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

Skip to content

Commit 8946c38

Browse files
committed
Fix hidpi in qt5cairo.
1 parent ab61783 commit 8946c38

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/matplotlib/backends/backend_qt5cairo.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ def __init__(self, figure):
1010

1111
def paintEvent(self, event):
1212
self._update_dpi()
13-
width = self.width()
14-
height = self.height()
13+
dpi_ratio = self._dpi_ratio
14+
width = dpi_ratio * self.width()
15+
height = dpi_ratio * self.height()
1516
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
1617
self._renderer.set_ctx_from_surface(surface)
1718
self._renderer.set_width_height(width, height)
@@ -23,6 +24,9 @@ def paintEvent(self, event):
2324
# QImage under PySide on Python 3.
2425
if QT_API == 'PySide' and six.PY3:
2526
ctypes.c_long.from_address(id(buf)).value = 1
27+
if hasattr(qimage, 'setDevicePixelRatio'):
28+
# Not available on Qt4 or some older Qt5.
29+
qimage.setDevicePixelRatio(dpi_ratio)
2630
painter = QtGui.QPainter(self)
2731
painter.drawImage(0, 0, qimage)
2832
self._draw_rect_callback(painter)

0 commit comments

Comments
 (0)