There is an ICO format image format plugin in Qt 4.8.4. I don't know exactly when it was added, but it has been around for quite a while. The code in that plugin is quite capable of loading the multiple images in ICO file but defaults to the first for non-animated formats. You can use the QImageReader directly to find the image you want. So, for this icon:
$ identify qtcreator.ico
qtcreator.ico[0] ICO 256x256 256x256+0+0 32-bit DirectClass 288KB 0.000u 0:00.009
qtcreator.ico[1] ICO 48x48 48x48+0+0 32-bit DirectClass 288KB 0.000u 0:00.000
qtcreator.ico[2] ICO 32x32 32x32+0+0 32-bit DirectClass 288KB 0.000u 0:00.000
qtcreator.ico[3] ICO 24x24 24x24+0+0 32-bit DirectClass 288KB 0.000u 0:00.000
qtcreator.ico[4] ICO 16x16 16x16+0+0 32-bit DirectClass 288KB 0.000u 0:00.000
$ identify qtcreator.ico
qtcreator.ico[0] ICO 256x256 256x256+0+0 32-bit DirectClass 288KB 0.000u 0:00.009
qtcreator.ico[1] ICO 48x48 48x48+0+0 32-bit DirectClass 288KB 0.000u 0:00.000
qtcreator.ico[2] ICO 32x32 32x32+0+0 32-bit DirectClass 288KB 0.000u 0:00.000
qtcreator.ico[3] ICO 24x24 24x24+0+0 32-bit DirectClass 288KB 0.000u 0:00.000
qtcreator.ico[4] ICO 16x16 16x16+0+0 32-bit DirectClass 288KB 0.000u 0:00.000
To copy to clipboard, switch view to plain text mode
This selects the 16x16 icon (and the first image if 16x16 is not matched):
#include <QtGui>
#include <QDebug>
int main(int argc, char **argv)
{
QImage result
= reader.
read();
// this acts as a default if the size is not matched for (int i = 0; i < reader.imageCount(); ++i) {
reader.jumpToImage(i);
if (image.
size() == QSize(16,
16)) { result = image;
break;
}
}
w.
setWindowIcon(QPixmap::fromImage(result
));
w.show();
return app.exec();
}
#include <QtGui>
#include <QDebug>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QImageReader reader("qtcreator.ico");
QImage result = reader.read(); // this acts as a default if the size is not matched
for (int i = 0; i < reader.imageCount(); ++i) {
reader.jumpToImage(i);
QImage image = reader.read();
if (image.size() == QSize(16, 16)) {
result = image;
break;
}
}
QWidget w;
w.setWindowIcon(QPixmap::fromImage(result));
w.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks