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

QIcon::pixmap(size) returns wrong size or QIcon::availableSized() is incorrect

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.2
    • Fix Version/s: None
    • Component/s: GUI: Painting
    • Labels:
      None
    • Platform/s:
      Windows

      Description

      QIcon returns wrong pixmap size. Consider the following code:

      #include <QApplication>
      #include <QFileIconProvider>
      #include <QDebug>
      #include <QLabel>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QLabel image;
          QFileIconProvider provider;
          QIcon icon = provider.icon(QFileInfo("path/to/some/file")); // for example some path to some shortcut *.lnk
          qInfo() << icon; // 256x256 is avilable!
          QPixmap pixmap = icon.pixmap(QSize(256, 256)); // I want this size!
          qInfo() << pixmap; // I don't get it!
          image.setPixmap(pixmap);
          image.show();
          return a.exec();
      }
      

      It writes these lines:

      QIcon(availableSizes[normal,Off]=(QSize(16, 16), QSize(32, 32), QSize(48, 48), QSize(256, 256)),cacheKey=0x100000000)
      QPixmap(QSize(32, 32),depth=32,devicePixelRatio=1,cacheKey=0x100000001)
      

      As you can see there is an available size of 256x256 but when I request pixmap of this size, it returns only pixmap of size 32x32.

      As documentation for QIcon::pixmap() says: "The pixmap might be smaller than requested, but never larger." In this sense, there is no bug - the returned pixmap (32x32) is smaller than requested (256x256). But I believe that in this case 256x256 should not be listed among available sizes.

      What is interesting: This happens only to some folders for which I try to get their icon via `QFIleIconProvider::icon(path)`. I am using TortoiseGit which install some icon extensions to Windows. This problem with wrong icon size is observable only for folders which are inside Git repository.

      But regardless of this, when QIcon claims it has available size 256x256 and I request it, then I believe correct behaviour should be to return it. Therefore I consider this to be a bug in Qt rather than some obscurity caused by TortoiseGit clashing with Windows.

      Btw. this is what I get by the program above:

      And this is the required icon as it can be seen as 256x256 icon in FileExplorer:

      UPDATE: as I found the very same problem occurs when I try to obtain 256x256 icon for a Windows shortcut. E.g. icon to "a.txt" works fine and returns 256x256 pixmap. But if I create a shortcut "a.txt.lnk", then this returns only 32x32 despite the fact that 256x256 is listed among available sizes. In other words, to replicate this behavior, use any path to a windows shortcut *.lnk.

        Attachments

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

          Activity

            People

            Assignee:
            vgt Eirik Aavitsland
            Reporter:
            vladimir.kraus Vladimir Kraus
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes