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

Too large SVG icon on low-DPI monitor on Retina Mac with QIcon::fromTheme and AA_UseHighDpiPixmaps

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.12.0
    • Fix Version/s: 5.15.0 Beta2
    • Component/s: GUI: Look'n'Feel
    • Labels:
      None
    • Environment:
      macOS 10.14.2
      MacBook Pro (Retina, 13-inch, Late 2013)
    • Platform/s:
      macOS
    • Commits:
      d8ab719c0890195cfce0fb6d4c76b3664d6f3a9d (qt/qtbase/5.15)

      Description

      Originally reported on the development mailing list here:

      https://lists.qt-project.org/pipermail/development/2019-April/035599.html

      The following test case:

      #include <QApplication>
      #include <QIcon>
      #include <QToolButton>
      
      int main(int argc, char *argv[]) {
          QApplication app(argc, argv);
      
          app.setAttribute(Qt::AA_UseHighDpiPixmaps);
      
          QIcon::setThemeName("mytheme");
      
          // Create icon from file name -> Size of pixmap is correct on both screens
          QToolButton button1;
          button1.setIcon(QIcon("icons/mytheme/scalable/actions/test-icon.svg"));
          button1.show();
      
          // Create icon from theme -> Size of pixmap is correct only on primary screen
          QToolButton button2;
          button2.setIcon(QIcon::fromTheme("test-icon"));
          button2.show();
      
          return app.exec();
      }
      

      Will produce this result when run on an external lower-DPI monitor hooked up to a Retina Mac:

      Note how the icon created using QIcon("icons/mytheme/scalable/actions/test-icon.svg") (left) has the correct size, while the one created using QIcon::fromTheme("test-icon") (right) has the wrong size for that monitor (the size is correct for the internal HiDPI screen).

      The app.setAttribute(Qt::AA_UseHighDpiPixmaps) is crucial. Without it, both icons have correct size on both monitors.

      There seems to be some bug in the icon engine used when using an icon through a theme that makes it not respect the device pixel ratio of the current screen, but instead use that of the primary screen (the built-in HiDPI screen).

      I've browsed through bug reports on QIcon + HiDPI + AA_UseHighDpiPixmaps but not found one quite like this. Sorry in advance if it's a duplicate!

      I'm attaching the full test case as a ZIP.

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              vestbo Tor Arne Vestbø
              Reporter:
              estan Elvis Stansvik
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes