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

QIcon::pixmap() returns pixmap with larger size than requested

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.1
    • GUI: Painting
    • None
    • Windows 10
    • Windows

    Description

      The documentation https://doc.qt.io/qt-5/qicon.html#pixmap says "The pixmap might be smaller than requested, but never larger, unless the device-pixel ratio of the returned pixmap is larger than 1."

      But in my code I request size 64x64 but obtain size 256x256, which is larger than requested size (with device-pixel ratio is still 1). See the code:

      #include <QApplication>
      #include <QLabel>
      #include <QFileIconProvider>
      #include <QIcon>
      #include <QPixmap>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QSize size = {64, 64};
          QFileIconProvider iconProvider;
          QIcon icon = iconProvider.icon(QFileInfo("C:/Windows"));
          QPixmap pixmap = icon.pixmap(size);
          qInfo() << size << pixmap.size() << pixmap.devicePixelRatio(); // prints QSize(64, 64) QSize(256, 256) 1
          QLabel w;
          w.setPixmap(pixmap);
          w.show();
          return a.exec();
      }
      

      Attachments

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

        Activity

          People

            sorvig Morten Sørvig
            vladimir.kraus Vladimir Kraus
            Veli-Pekka Heinonen Veli-Pekka Heinonen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes