Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-90363

Blurry title bar and task bar icons on Windows with fractional DPI scaling

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4: Low
    • Resolution: Done
    • Affects Version/s: 6.0.0
    • Fix Version/s: 6.1.0 Alpha
    • Component/s: QPA: Windows
    • Labels:
      None
    • Platform/s:
      Windows
    • Commits:
      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).

        Attachments

        1. qtbug90363_diag.diff
          0.6 kB
        2. qtbug90363_log.txt
          2 kB
        3. qtbug90363.jpg
          qtbug90363.jpg
          108 kB
        4. qtbug90363.zip
          40 kB
        5. repro2.zip
          37 kB
        6. reproducer showing bug.png
          reproducer showing bug.png
          7 kB
        7. reproducer with workaround enabled showing expected result.png
          reproducer with workaround enabled showing expected result.png
          7 kB
        For Gerrit Dashboard: QTBUG-90363
        # Subject Branch Project Status CR V

          Activity

            People

            Assignee:
            kleint Friedemann Kleint
            Reporter:
            bbouclet Bastien Bouclet
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes