Results 1 to 4 of 4

Thread: setWindowIcon() with ICO format

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: setWindowIcon() with ICO format

    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:
    Qt Code:
    1. $ identify qtcreator.ico
    2. qtcreator.ico[0] ICO 256x256 256x256+0+0 32-bit DirectClass 288KB 0.000u 0:00.009
    3. qtcreator.ico[1] ICO 48x48 48x48+0+0 32-bit DirectClass 288KB 0.000u 0:00.000
    4. qtcreator.ico[2] ICO 32x32 32x32+0+0 32-bit DirectClass 288KB 0.000u 0:00.000
    5. qtcreator.ico[3] ICO 24x24 24x24+0+0 32-bit DirectClass 288KB 0.000u 0:00.000
    6. 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):
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. QImageReader reader("qtcreator.ico");
    9. QImage result = reader.read(); // this acts as a default if the size is not matched
    10. for (int i = 0; i < reader.imageCount(); ++i) {
    11. reader.jumpToImage(i);
    12. QImage image = reader.read();
    13. if (image.size() == QSize(16, 16)) {
    14. result = image;
    15. break;
    16. }
    17. }
    18.  
    19. w.setWindowIcon(QPixmap::fromImage(result));
    20. w.show();
    21.  
    22. return app.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to ChrisW67 for this useful post:

    cic (4th July 2013)

Similar Threads

  1. setWindowIcon
    By dragon in forum Qt Tools
    Replies: 3
    Last Post: 3rd December 2012, 06:41
  2. Replies: 0
    Last Post: 13th October 2011, 16:22
  3. setWindowIcon function
    By Peppy in forum Qt Programming
    Replies: 5
    Last Post: 9th November 2009, 09:46
  4. Qt3 to Qt4 transition, setWindowIcon() problems
    By watashi16 in forum Qt Programming
    Replies: 5
    Last Post: 13th December 2007, 20:18
  5. Can setWindowIcon() work in QDockWidget?
    By alfa_wu in forum Qt Programming
    Replies: 2
    Last Post: 13th December 2007, 08:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.