diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index 4e3c37afad..8ce18b7dc8 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -289,7 +289,10 @@ class CoverView(QWidget): # {{{ target = QRect(x, y, width, height) p = QPainter(self) p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) - dpr = self.devicePixelRatio() + try: + dpr = self.devicePixelRatioF() + except AttributeError: + dpr = self.devicePixelRatio() spmap = self.pixmap.scaled(target.size() * dpr, Qt.KeepAspectRatio, Qt.SmoothTransformation) spmap.setDevicePixelRatio(dpr) p.drawPixmap(target, spmap) diff --git a/src/calibre/gui2/dialogs/book_info.py b/src/calibre/gui2/dialogs/book_info.py index fdd5425678..520b4edd51 100644 --- a/src/calibre/gui2/dialogs/book_info.py +++ b/src/calibre/gui2/dialogs/book_info.py @@ -166,7 +166,10 @@ class BookInfo(QDialog): pixmap.height(), self.cover.size().width()-10, self.cover.size().height()-10) if scaled: - dpr = self.devicePixelRatio() + try: + dpr = self.devicePixelRatioF() + except AttributeError: + dpr = self.devicePixelRatio() pixmap = pixmap.scaled(int(dpr * new_width), int(dpr * new_height), Qt.KeepAspectRatio, Qt.SmoothTransformation) pixmap.setDevicePixelRatio(dpr) @@ -200,7 +203,11 @@ class BookInfo(QDialog): self.current_row = row self.setWindowTitle(mi.title) self.cover_pixmap = QPixmap.fromImage(mi.cover_data[1]) - self.cover_pixmap.setDevicePixelRatio(self.devicePixelRatio()) + try: + dpr = self.devicePixelRatioF() + except AttributeError: + dpr = self.devicePixelRatio() + self.cover_pixmap.setDevicePixelRatio(dpr) self.resize_cover() html = render_html(mi, self.css, True, self, all_fields=True) self.details.setHtml(html) diff --git a/src/calibre/gui2/icon_theme.py b/src/calibre/gui2/icon_theme.py index 6da70effd3..c486e688bf 100644 --- a/src/calibre/gui2/icon_theme.py +++ b/src/calibre/gui2/icon_theme.py @@ -688,9 +688,13 @@ class ChooseTheme(Dialog): def set_cover(self, theme, cdata): theme['cover-pixmap'] = p = QPixmap() + try: + dpr = self.devicePixelRatioF() + except AttributeError: + dpr = self.devicePixelRatio() if isinstance(cdata, bytes): p.loadFromData(cdata) - p.setDevicePixelRatio(self.devicePixelRatio()) + p.setDevicePixelRatio(dpr) item = self.item_from_name(theme['name']) if item is not None: item.setData(Qt.DecorationRole, p) diff --git a/src/calibre/gui2/metadata/pdf_covers.py b/src/calibre/gui2/metadata/pdf_covers.py index 8d5282e3a7..66e95d552c 100644 --- a/src/calibre/gui2/metadata/pdf_covers.py +++ b/src/calibre/gui2/metadata/pdf_covers.py @@ -110,9 +110,14 @@ class PDFCovers(QDialog): self.reject() return + try: + dpr = self.devicePixelRatioF() + except AttributeError: + dpr = self.devicePixelRatio() + for i, f in enumerate(sorted(files)): - p = QPixmap(f).scaled(self.covers.iconSize()*self.devicePixelRatio(), aspectRatioMode=Qt.IgnoreAspectRatio, transformMode=Qt.SmoothTransformation) - p.setDevicePixelRatio(self.devicePixelRatio()) + p = QPixmap(f).scaled(self.covers.iconSize()*dpr, aspectRatioMode=Qt.IgnoreAspectRatio, transformMode=Qt.SmoothTransformation) + p.setDevicePixelRatio(dpr) i = QListWidgetItem(_('page %d') % (i + 1)) i.setData(Qt.DecorationRole, p) i.setData(Qt.UserRole, f) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index b95b02c57e..ba236bb42f 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -240,7 +240,11 @@ class Background(QWidget): # {{{ path = texture_path(self.btex) if path: p = QPixmap(path) - p.setDevicePixelRatio(self.devicePixelRatio()) + try: + dpr = self.devicePixelRatioF() + except AttributeError: + dpr = self.devicePixelRatio() + p.setDevicePixelRatio(dpr) self.brush.setTexture(p) self.update() diff --git a/src/calibre/gui2/tweak_book/editor/canvas.py b/src/calibre/gui2/tweak_book/editor/canvas.py index 4162418f4a..8278d1f25f 100644 --- a/src/calibre/gui2/tweak_book/editor/canvas.py +++ b/src/calibre/gui2/tweak_book/editor/canvas.py @@ -595,7 +595,10 @@ 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() + try: + dpr = self.devicePixelRatioF() + except AttributeError: + dpr = self.devicePixelRatio() if scaled: i = self.current_image.scaled(int(dpr * width), int(dpr * height), transformMode=Qt.SmoothTransformation) self.current_scaled_pixmap = QPixmap.fromImage(i) @@ -604,7 +607,10 @@ class Canvas(QWidget): @painter def draw_pixmap(self, painter): p = self.current_scaled_pixmap - dpr = self.devicePixelRatio() + try: + dpr = self.devicePixelRatioF() + except AttributeError: + 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.)