Icon sizes incorrect



  • Hi all,

    I have an icon which contains the sizes: 16x16, 32x32, 48x48 and 256x256. In my application, I would like to use the 32x32 size in the Windows taskbar, however 16x16 in the top left corner of my message box's, open dialogs etc.

    When I use setWindowIcon() on either my application or main window, it only ever uses the 16x16 icon. So in the taskbar it stretches it to 32x32 and is pixelated.

    When I use an RC file, it only ever uses the 32x32 icon, which is scaled down in my message boxes etc and looks rubbish. Interestingly when using the RC file, my exe file in Windows explorer uses the correct icon depending on the size it has available, as desired.

    All documents I have read online suggest that QT should look after this automatically. Just wondering if someone has come accross the same problem, or if you may have an idea of something to try?

    Thanks,
    Damien



  • To get around this issue I have set a different icon for my application and main window. All my application dialogs (i.e. message boxes) use the smaller icon, and the main window uses the larger icon for the taskbar. Far from ideal but seems to work thus far:

    @
    QImageReader reader(":qml/images/icon.ico");
    QImage img;

    reader.jumpToImage(0);
    img = reader.read();
    app.setWindowIcon(QIcon(QPixmap::fromImage(img)));

    reader.jumpToImage(2);
    img = reader.read();
    mw.setWindowIcon(QIcon(QPixmap::fromImage(img)));
    @

    My only remaining issue is when I call QFileDialog::getOpenFileName() it takes the main window icon instead of the application dialog, regardless of whether i set its parent to "0" or "this". I have even tried changing the parent to the main windows parent (i.e. the application). It still takes the main windows icon!

    Any suggestions? Is there a way to change the open dialogs icon manually?

    Thanks,
    Damien



  • I know that post is old, but it may help late readers like me.

    bq. All documents I have read online suggest that QT should look after this automatically. Just wondering if someone has come accross the same problem, or if you may have an idea of something to try?

    True, in fact it does. However, I think that the .ico imageformat plugin doesn't load multiple sizes or using the QIcon(const QString &) constructor assume that only one image can be read in the given file.

    Here's a workaround to insert all sizes of an .ico file into a QIcon object (based on Fuzz1985 idea)

    @QIcon readIcoFile(const QString & path)
    {
    QImageReader ir(path)
    QIcon icon;

    if (ir.canRead())
    {
    do
    {
    icon.addPixmap(QPixmap::fromImage(ir.read()));
    }
    while (ir.jumpToNextImage());
    }

    return icon;
    }@



  • This post is deleted!

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.