From eee8b83f9a84ce27a42ffc6d500f67a6151c832a Mon Sep 17 00:00:00 2001 From: David Korth Date: Sun, 15 Jun 2025 11:17:42 -0400 Subject: [PATCH] [kde] ListDataModel::updateIconPixmaps(): Improve icon scaling on Qt5 and Qt6. Instead of scaling larger icons down, set a device pixel ratio. For the usual case of iconSize = (32, 32), on a 200% display, the actual physical icon size is (64, 64). Xbox 360 achievement icons are 64x64, so this will show the full icon on a 200% display instead of scaling down to 32x32, then scaling back up to 64x64. For icons smaller than 32x32, the icon is scaled up using integer factors to the next highest integer multiple that's >= 32x32, then the device pixel ratio is set. NOTE: GTK+ doesn't seem to have the same issue. TODO: Verify Win32, especially with icon directories. --- src/kde/ListDataModel.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/kde/ListDataModel.cpp b/src/kde/ListDataModel.cpp index 1ae067c36..73ad0d322 100644 --- a/src/kde/ListDataModel.cpp +++ b/src/kde/ListDataModel.cpp @@ -179,6 +179,28 @@ void ListDataModelPrivate::updateIconPixmaps(void) QPixmap pixmap = QPixmap::fromImage(rpToQImage(img)); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + // NOTE: Assuming square pixmaps. + if (img->width() > iconSize.width()) { + // Instead of scaling icons down, set a device pixel ratio. + // This allows for higher-resolution display on high-DPI screens. + pixmap.setDevicePixelRatio(static_cast(img->width()) / static_cast(iconSize.width())); + } else { + // Scale up using integer scaling, then set a device pixel ratio. + int w = img->width(); + int h = img->height(); + if (w <= 0) { + continue; + } + while (w < iconSize.width()) { + w += img->width(); + h += img->height(); + } + pixmap = pixmap.scaled(w, h, Qt::KeepAspectRatio, Qt::FastTransformation); + + pixmap.setDevicePixelRatio(static_cast(w) / static_cast(iconSize.width())); + } +#else /* QT_VERSION < QT_VERSION_CHECK(5, 0, 0) */ // Do we need to resize the icon? if (img->width() != iconSize.width() || img->height() != iconSize.height()) @@ -186,6 +208,7 @@ void ListDataModelPrivate::updateIconPixmaps(void) // Resize is needed. pixmap = pixmap.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } +#endif /* QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) */ icons.push_back(std::move(pixmap)); }