[kde] ListDataModel::updateIconPixmaps(): Improve icon scaling on Qt5 and Qt6.
Some checks are pending
Codecov / run (push) Waiting to run
CodeQL / Analyze (cpp) (push) Waiting to run

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.
This commit is contained in:
David Korth 2025-06-15 11:17:42 -04:00
parent b19f128903
commit eee8b83f9a

View File

@ -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<qreal>(img->width()) / static_cast<qreal>(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<qreal>(w) / static_cast<qreal>(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));
}