From 7e965e842450e52226d08db13f8ce8dba737db07 Mon Sep 17 00:00:00 2001 From: cosven Date: Wed, 31 Jul 2024 21:08:11 +0800 Subject: [PATCH] refine code --- feeluown/gui/uimain/page_view.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/feeluown/gui/uimain/page_view.py b/feeluown/gui/uimain/page_view.py index eecdbc3cf4..50eb030670 100644 --- a/feeluown/gui/uimain/page_view.py +++ b/feeluown/gui/uimain/page_view.py @@ -270,17 +270,14 @@ def _draw_overlay(self, painter, draw_width, draw_height, scrolled): def _draw_pixmap(self, painter, draw_width, draw_height, scrolled): # scale pixmap assert self._pixmap is not None - scaled_pixmap = self._pixmap.scaledToWidth( - draw_width, - mode=Qt.SmoothTransformation) + pixmap_size = self._pixmap.size() # draw the center part of the pixmap on available rect painter.save() - if scaled_pixmap.height() < draw_height: + if pixmap_size.width() / draw_width * draw_height >= pixmap_size.height(): scaled_pixmap = self._pixmap.scaledToHeight( draw_height, - mode=Qt.SmoothTransformation - ) + mode=Qt.SmoothTransformation) brush = QBrush(scaled_pixmap) painter.setBrush(brush) pixmap_size = scaled_pixmap.size() @@ -288,6 +285,9 @@ def _draw_pixmap(self, painter, draw_width, draw_height, scrolled): painter.translate(-x, -scrolled) rect = QRect(0, 0, pixmap_size.width(), draw_height) else: + scaled_pixmap = self._pixmap.scaledToWidth( + draw_width, + mode=Qt.SmoothTransformation) pixmap_size = scaled_pixmap.size() brush = QBrush(scaled_pixmap) painter.setBrush(brush)