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

QIcon::pixmap selects wrong icon file from theme

XMLWordPrintable

    • All
    • 46e7060ee (dev), 0cff18f1a (6.10), 1f9319ea9 (6.9), 29c3b512d (dev), b0adf2dcb (6.10), f4bce5b40 (6.9)

      Creating a pixmap from a QIcon will sometimes choose the wrong icon file depending on the theme and scale. In this example with the Adwaita theme it chose the 16x16 png instead of the svg, which is much worse for the requested size and scale.

      #include <QtWidgets>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          QIcon::setThemeName("Adwaita");
          QIcon icon = QIcon::fromTheme(QStringLiteral("folder-documents"));
          qDebug() << icon.availableSizes(); // QList(QSize(16, 16), QSize(128, 128))
          QPixmap pixmapRegular = icon.pixmap(QSize(128, 128), 1.0);
          qDebug() << pixmapRegular.size(); // QSize(128, 128): OK
          QPixmap pixmapScaled = icon.pixmap(QSize(128, 128), 2.0);
          qDebug() << pixmapScaled.size(); //  QSize(16, 16): wrong
      }
      

        For Gerrit Dashboard: QTBUG-137700
        # Subject Branch Project Status CR V

            chehrlic Christian Ehrlicher
            dernett Alexander Burnett
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: