Skip to content

Cairo rendering for Qt5 #8771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
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