Details
-
Bug
-
Resolution: Done
-
P4: Low
-
6.0.0
-
None
-
-
341b0ef501178b156c7aa5efaf6b6b72a039508c (qt/qtbase/dev)
Description
On my Windows 10 (1909) system, when DPI scaling is set to 125%, the title bar icon of my Qt application is blurry. Which such settings, Windows displays a 20x20px icon. The QIcon I provide to `QGuiApplication::setWindowIcon` contains a pixmap with that resolution, therefore I expect the icon to be displayed as is.
The responsible code appears to be here: https://github.com/qt/qtbase/blob/d7d6f8765f709dd4162a0d39404969d39b6d4b00/src/plugins/platforms/windows/qwindowswindow.cpp#L2936-L2962
static HICON createHIcon(const QIcon &icon, int xSize, int ySize) { if (!icon.isNull()) { const QPixmap pm = icon.pixmap(icon.actualSize(QSize(xSize, ySize))); if (!pm.isNull()) return qt_pixmapToWinHICON(pm); } return nullptr; }
In this snippet, `icon.actualSize` returns `{ 20, 20 }` as expected. The pixmap returned by `icon.pixmap` is `{ 25, 25 }` (which is correct as per QIcon documentation 20 * 1,25 = 25).
To produce this pixmap, QIcon had to scale a pixmap with a different size. The HICON is then passed to Windows which will scale it down to 20x20px for display.
This double scaling results in poor visual quality.
Using the overload of `QIcon::Pixmap()` that takes `devicePixelRatio` with a value of 1 seems to be a quick fix for this issue. (It's probably not a full fix as GetSystemMetrics is not per-screen DPI aware, and the `@2x` QIcon pixmaps are not handled properly).