Skip to content
Prev Previous commit
Fix hidpi in qt5cairo.
  • Loading branch information
anntzer committed Jan 9, 2018
commit 8946c385940e83b44bc80738a2dd1a66b4afc555
8 changes: 6 additions & 2 deletions lib/matplotlib/backends/backend_qt5cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ def __init__(self, figure):

def paintEvent(self, event):
self._update_dpi()
width = self.width()
height = self.height()
dpi_ratio = self._dpi_ratio
width = dpi_ratio * self.width()
height = dpi_ratio * self.height()
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
self._renderer.set_ctx_from_surface(surface)
self._renderer.set_width_height(width, height)
Expand All @@ -23,6 +24,9 @@ def paintEvent(self, event):
# QImage under PySide on Python 3.
if QT_API == 'PySide' and six.PY3:
ctypes.c_long.from_address(id(buf)).value = 1
if hasattr(qimage, 'setDevicePixelRatio'):
# Not available on Qt4 or some older Qt5.
qimage.setDevicePixelRatio(dpi_ratio)
painter = QtGui.QPainter(self)
painter.drawImage(0, 0, qimage)
self._draw_rect_callback(painter)
Expand Down