From bc6e4b8813924df821e067534e782ec510c70e9f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 25 Aug 2016 08:33:19 +0530 Subject: [PATCH] Fix high DPI rendering for the iamge editor widget in Edit Book --- src/calibre/gui2/tweak_book/editor/canvas.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/canvas.py b/src/calibre/gui2/tweak_book/editor/canvas.py index 4867bd4bba..4162418f4a 100644 --- a/src/calibre/gui2/tweak_book/editor/canvas.py +++ b/src/calibre/gui2/tweak_book/editor/canvas.py @@ -595,14 +595,17 @@ class Canvas(QWidget): i = self.current_image width, height = i.width(), i.height() scaled, width, height = fit_image(width, height, pwidth, pheight) + dpr = self.devicePixelRatio() if scaled: - i = self.current_image.scaled(width, height, transformMode=Qt.SmoothTransformation) + i = self.current_image.scaled(int(dpr * width), int(dpr * height), transformMode=Qt.SmoothTransformation) self.current_scaled_pixmap = QPixmap.fromImage(i) + self.current_scaled_pixmap.setDevicePixelRatio(dpr) @painter def draw_pixmap(self, painter): p = self.current_scaled_pixmap - width, height = p.width(), p.height() + dpr = self.devicePixelRatio() + width, height = int(p.width()/dpr), int(p.height()/dpr) pwidth, pheight = self.last_canvas_size x = int(abs(pwidth - width)/2.) y = int(abs(pheight - height)/2.)