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

Windows Icon Engine: QIcon::pixmap() scales size by devicePixelRatio twice, not once

    XMLWordPrintable

Details

    • All
    • 245bdc8ec (dev), bf1d4023f (6.8)

    Description

      Using the new Windows platform icon engine that was enabled with the Qt 6.7 release, I have this code:

      auto icon = QIcon::fromTheme("document-open");
      auto pixmap = icon.pixmap({ 20, 20 }, 1.5);
      
      qDebug() << pixmap.devicePixelRatio();
      qDebug() << pixmap.size();
      

      Which outputs:

      2.25
      QSize(45, 45)
      

      But as the code requests a device pixel ratio of 1.5, I would expect the output to be:

      1.5
      QSize(30, 30)
      

      This happens because inside QWindowsIconEngine::scaledPixmap() when creating the QPixmap the size is multiplied by scale, but it has already been multiplied by scale inside QIcon::pixmap() when passing the size parameter to the engine scaledPixmap() virtual method.

      After return from scaledPixmap(), QIconPrivate::pixmapDevicePixelRatio() looks at the actual size of the QPixmap returned and calculates the actual devicePixelRatio based on that, 45 ÷ 20 = 2.25, so that's what it gets set to.

      I'm thinking should only be multiplying size by scale once, not twice. So therefore, suggest that one of the duplicate multiplications gets removed.

      The other new platform icon engines should probably be checked also.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              sorvig Morten Sørvig
              jamesg-nz James Grant
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes