QIcon::pixmap(size) returns wrong size – any workaround?

  c++, qt

This issue is probably a bug in Qt which I have just reposted at https://bugreports.qt.io/browse/QTBUG-95999 But until it gets fixed I would need any workaround. Unfortunately I cannot find any. Any ideas?

The problem is this: QIcon returns wrong pixmap size. And I need it to return correct 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/folder"));
  qInfo() << icon; // 256x256 is available!
  QPixmap pixmap = icon.pixmap(QSize(256, 256)); // I want it!
  qInfo() << pixmap; // I don't get it!
  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 256×256 but when I request pixmap of this size, it returns only pixmap of size 32×32.

What is interesting: This happens only to some folders for which I try to get their icon via QFIleIconProvider. 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. For other folders I get 256×256 icons without problems.

But regardless of this, when QIcon claims it has available size 256×256 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 – a pathetic 32×32 icon:

enter image description here

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

enter image description here

Source: Windows Questions C++