Results 1 to 9 of 9

Thread: Retrieving a file's icon

  1. #1

    Default Retrieving a file's icon

    Hello,

    Is there any way to retrieve the icon of a file given the file's pathname? In particular, I am attempting to retrieve an application's icon.

    I have been able to do this for Windows using SHGetFileInfo(), but my application needs to be cross-platform and this (obviously) won't work for Mac or Linux.

    I have also tried the following:
    Qt Code:
    1. QString file = "C:\application.exe";
    2. QFileInfo fileInfo( file );
    3. QFileIconProvider fileIconProvider;
    4. QIcon appIcon = fileIconProvider.icon( fileInfo );
    To copy to clipboard, switch view to plain text mode 
    However this always returns the system's default icon for folders and files rather than the file's specific icon.

    Any suggestions or thoughts on how I could do this would be most appreciated.
    (I'm using Qt 4.2.2)

    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Retrieving a file's icon

    Notice a missing escape character:
    Qt Code:
    1. QString file = "C:\\application.exe";
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Retrieving a file's icon

    HI, following a topic - does anyone knows way to extract icons stored in dll's resources?

  4. #4
    Join Date
    Jan 2007
    Posts
    177
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

  5. The following user says thank you to kernel_panic for this useful post:

    mchara (30th October 2007)

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Retrieving a file's icon

    And once you start converting HICON to QIcon/QPixmap, notice convertHIconToPixmap() in src/gui/image/qpixmap_win.cpp
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    mchara (30th October 2007)

  8. #6
    Join Date
    Jan 2007
    Posts
    177
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving a file's icon

    yep forgot that.
    i prefer this solution:
    http://www.methylblue.com/blog/hicon-to-qpixmap/

  9. #7
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Retrieving a file's icon

    Thanks, that answers all my questions in this topic.

  10. #8
    Join Date
    Feb 2008
    Posts
    60
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving a file's icon

    Dear all,

    can anyone help me to save QIcon as an image file.

    Thanks in advance.

  11. #9
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Retrieving a file's icon

    I'm not sure, because recently i had no time for programming private project(i got enough at work), but as far as i remember, i have made some changes in qt imageformat plugin for ico format taken from kde sources.
    Kde had writing to ico files method in qt3 but after migration to qt 4 only ico reading was ported and writing method was commented and i reworked it (using some other open software as reference(i don't remember its name now) so it saves ico files in current version(of course it's limited implementation and it doesn't support all possible formats)

    http://downloads.sourceforge.net/gra...8&big_mirror=0

    i hope it will work for you(i didn't tested in on any linux)
    CU
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

Similar Threads

  1. Mac application and the Dock Icon
    By sekelsenmat in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2007, 10:23
  2. Replies: 5
    Last Post: 22nd September 2006, 08:04
  3. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.