Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Icon sizes incorrect
Forum Updated to NodeBB v4.3 + New Features

Icon sizes incorrect

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fuzz1985
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fuzz1985
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GMatte
        wrote on last edited by
        #3

        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;
        }@

        1 Reply Last reply
        0
        • Andy314A Offline
          Andy314A Offline
          Andy314
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved