From f4b64f9c12a6351008a08bfeb4540481edf9f1d0 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 6 Jan 2025 19:44:36 +0100 Subject: [PATCH] WindowsTheme: Draw icon overlay manually instead of relying on the api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix drawing the link overlay icon - we must not set the device pixel ratio here as we don't know the exact value. Also fix some styling issues introduced with the previous commit. This amends fd7bc16e9fbdc63bd22ba90d0c20b36ccffd2bae. Pick-to: 6.9 6.8 Task-number: QTBUG-131843 Change-Id: I382527d17e8187bfae7cf40f352e6f87965671a1 Reviewed-by: Tor Arne Vestbø --- .../platforms/windows/qwindowstheme.cpp | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 63d14756291..e908f6d646a 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -903,20 +903,19 @@ QPixmap QWindowsTheme::standardPixmap(StandardPixmap sp, const QSizeF &pixmapSiz break; } - // Even with SHGSI_LINKOVERLAY flag set, loaded Icon with SHDefExtractIcon doesn't have - // any overlay, so we avoid SHGSI_LINKOVERLAY flag and draw it manually (QTBUG-131843) - const auto drawLinkOverlayIcon = [](StandardPixmap sp, QPixmap &pixmap, QSizeF pixmapSize) { + // Even with SHGSI_LINKOVERLAY flag set, loaded Icon with SHDefExtractIcon doesn't have + // any overlay, so we avoid SHGSI_LINKOVERLAY flag and draw it manually (QTBUG-131843) + const auto drawLinkOverlayIconIfNeeded = [](StandardPixmap sp, QPixmap &pixmap, QSizeF pixmapSize) { if (sp == FileLinkIcon || sp == DirLinkIcon || sp == DirLinkOpenIcon) { QPainter painter(&pixmap); const QSizeF linkSize = pixmapSize / (pixmapSize.height() >= 48 ? 3 : 2); - const QPixmap link = loadIconFromShell32(16769, linkSize.toSize()); // 16769 = LinkOverlayIcon + static constexpr auto LinkOverlayIconId = 16769; + const QPixmap link = loadIconFromShell32(LinkOverlayIconId, linkSize.toSize()); const int yPos = pixmap.height() - link.size().height(); painter.drawPixmap(0, yPos, int(linkSize.width()), int(linkSize.height()), link); } }; - const auto dpr = qGuiApp->devicePixelRatio(); // Highest in the system - if (stockId != SIID_INVALID) { SHSTOCKICONINFO iconInfo; memset(&iconInfo, 0, sizeof(iconInfo)); @@ -927,12 +926,11 @@ QPixmap QWindowsTheme::standardPixmap(StandardPixmap sp, const QSizeF &pixmapSiz HICON icon; if (SHDefExtractIcon(iconInfo.szPath, iconInfo.iIcon, 0, &icon, nullptr, iconSize) == S_OK) { QPixmap pixmap = qt_pixmapFromWinHICON(icon); - if (!pixmap.isNull()) { - drawLinkOverlayIcon(sp, pixmap, pixmap.size()); - pixmap.setDevicePixelRatio(dpr); - } DestroyIcon(icon); - return pixmap; + if (!pixmap.isNull()) { + drawLinkOverlayIconIfNeeded(sp, pixmap, pixmap.size()); + return pixmap; + } } } } @@ -940,8 +938,7 @@ QPixmap QWindowsTheme::standardPixmap(StandardPixmap sp, const QSizeF &pixmapSiz if (resourceId != -1) { QPixmap pixmap = loadIconFromShell32(resourceId, pixmapSize); if (!pixmap.isNull()) { - drawLinkOverlayIcon(sp, pixmap, pixmapSize); - pixmap.setDevicePixelRatio(dpr); + drawLinkOverlayIconIfNeeded(sp, pixmap, pixmapSize); return pixmap; } }