From 5082280c0e48dec33000e5b71bdafd4068cc9f57 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 6 Sep 2023 11:59:36 +0530 Subject: [PATCH] Fix extra qpainter end() call --- src/calibre/gui2/widgets.py | 51 +++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index 16db2cd558..033431388a 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -371,36 +371,33 @@ class ImageView(QWidget, ImageDropMixin): pmap = self._pixmap p = QPainter(self) p.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform) - try: - if pmap.isNull(): - if self.draw_empty_border: - pen = QPen() - pen.setWidth(self.BORDER_WIDTH) - p.setPen(pen) - p.drawRect(self.rect()) - p.end() - return - w, h = pmap.width(), pmap.height() - ow, oh = w, h - cw, ch = self.rect().width(), self.rect().height() - scaled, nw, nh = fit_image(w, h, cw, ch) - if scaled: - pmap = pmap.scaled(int(nw*pmap.devicePixelRatio()), int(nh*pmap.devicePixelRatio()), Qt.AspectRatioMode.IgnoreAspectRatio, - Qt.TransformationMode.SmoothTransformation) - w, h = int(pmap.width()/pmap.devicePixelRatio()), int(pmap.height()/pmap.devicePixelRatio()) - x = int(abs(cw - w)/2) - y = int(abs(ch - h)/2) - target = QRect(x, y, w, h) - p.drawPixmap(target, pmap) - if self.draw_border: + if pmap.isNull(): + if self.draw_empty_border: pen = QPen() pen.setWidth(self.BORDER_WIDTH) p.setPen(pen) - p.drawRect(target) - if self.show_size: - draw_size(p, target, ow, oh) - finally: - p.end() + p.drawRect(self.rect()) + p.end() + return + w, h = pmap.width(), pmap.height() + ow, oh = w, h + cw, ch = self.rect().width(), self.rect().height() + scaled, nw, nh = fit_image(w, h, cw, ch) + if scaled: + pmap = pmap.scaled(int(nw*pmap.devicePixelRatio()), int(nh*pmap.devicePixelRatio()), Qt.AspectRatioMode.IgnoreAspectRatio, + Qt.TransformationMode.SmoothTransformation) + w, h = int(pmap.width()/pmap.devicePixelRatio()), int(pmap.height()/pmap.devicePixelRatio()) + x = int(abs(cw - w)/2) + y = int(abs(ch - h)/2) + target = QRect(x, y, w, h) + p.drawPixmap(target, pmap) + if self.draw_border: + pen = QPen() + pen.setWidth(self.BORDER_WIDTH) + p.setPen(pen) + p.drawRect(target) + if self.show_size: + draw_size(p, target, ow, oh) # }}}