From 76aab86de2e4345c9d7ad4b628d298c0c5c9bd6a Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 11 Dec 2023 11:50:52 +0100 Subject: [PATCH] QWindowsTheme: honor dpr when requesting standard icons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The devicePixelRatio was not taken into account when a standard icon was requested from the windows qpa which resulted in blurry icons for a dpr != 1. Therefore pass the dpr-corrected size to QWindowsTheme::standardPixmap() and pass this size to SHDefExtractIcon() to get a correctly scaled icon. Pick-to: 6.6 Fixes: QTBUG-52622 Change-Id: Ia771dd2f93fa133cf2c4429ef59a9c5cb05ad047 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 20cdc663b420a332d16f5f1ca82f352924cd7d1d) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/windows/qwindowstheme.cpp | 15 +++++++++------ src/widgets/styles/qcommonstyle.cpp | 13 +++++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index aeb8d4ad1b4..edebbb6d2f8 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -943,15 +943,18 @@ QPixmap QWindowsTheme::standardPixmap(StandardPixmap sp, const QSizeF &pixmapSiz } if (stockId != SIID_INVALID) { - QPixmap pixmap; SHSTOCKICONINFO iconInfo; memset(&iconInfo, 0, sizeof(iconInfo)); iconInfo.cbSize = sizeof(iconInfo); - stockFlags |= (pixmapSize.width() > 16 ? SHGFI_LARGEICON : SHGFI_SMALLICON); - if (SHGetStockIconInfo(stockId, SHGFI_ICON | stockFlags, &iconInfo) == S_OK) { - pixmap = qt_pixmapFromWinHICON(iconInfo.hIcon); - DestroyIcon(iconInfo.hIcon); - return pixmap; + stockFlags |= SHGSI_ICONLOCATION; + if (SHGetStockIconInfo(stockId, stockFlags, &iconInfo) == S_OK) { + const auto iconSize = pixmapSize.width(); + HICON icon; + if (SHDefExtractIcon(iconInfo.szPath, iconInfo.iIcon, 0, &icon, nullptr, iconSize) == S_OK) { + QPixmap pixmap = qt_pixmapFromWinHICON(icon); + DestroyIcon(icon); + return pixmap; + } } } diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 106536cb028..57d823171ff 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -5616,8 +5616,10 @@ QIcon QCommonStylePrivate::iconFromWindowsTheme(QCommonStyle::StandardPixmap sta case QStyle::SP_MessageBoxQuestion: if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { QPlatformTheme::StandardPixmap sp = static_cast(standardIcon); - for (int size = 16 ; size <= 32 ; size += 16) { - QPixmap pixmap = theme->standardPixmap(sp, QSizeF(size, size)); + const auto dpr = qt_getDevicePixelRatio(widget); + for (const int size : {16, 32}) { + QPixmap pixmap = theme->standardPixmap(sp, QSizeF(size, size) * dpr); + pixmap.setDevicePixelRatio(dpr); icon.addPixmap(pixmap, QIcon::Normal); } } @@ -5628,11 +5630,14 @@ QIcon QCommonStylePrivate::iconFromWindowsTheme(QCommonStyle::StandardPixmap sta QPlatformTheme::StandardPixmap spOff = static_cast(standardIcon); QPlatformTheme::StandardPixmap spOn = standardIcon == QStyle::SP_DirIcon ? QPlatformTheme::DirOpenIcon : QPlatformTheme::DirLinkOpenIcon; - for (int size = 16 ; size <= 32 ; size += 16) { - QSizeF pixSize(size, size); + const auto dpr = qt_getDevicePixelRatio(widget); + for (const int size : {16, 32}) { + const QSizeF pixSize = QSizeF(size, size) * dpr; QPixmap pixmap = theme->standardPixmap(spOff, pixSize); + pixmap.setDevicePixelRatio(dpr); icon.addPixmap(pixmap, QIcon::Normal, QIcon::Off); pixmap = theme->standardPixmap(spOn, pixSize); + pixmap.setDevicePixelRatio(dpr); icon.addPixmap(pixmap, QIcon::Normal, QIcon::On); } }