Results 1 to 16 of 16

Thread: Extracting larger icons

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Extracting larger icons

    I don't know about a Qt way (it seems to only return a single icon, either the small or the big depending on which is available), but on Windows you can get the icon via SHGetFileInfo() and then use the convertHIconToPixmap function in qpixmap_win.cpp (which has a big fat warning at the top of the file, so you need to either copy the code and be GPL licensed or write your own version).

  2. #2
    Join Date
    Apr 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: Extracting larger icons

    Thanks, that's worth a try! I'll come back as soon as I had time to try it.

  3. #3
    Join Date
    Apr 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: Extracting larger icons

    I've now tried using SHGetFileInfo() the following way:

    Qt Code:
    1. LPCTSTR path = (LPCTSTR)filePath.toStdString().c_str();
    2. SHFILEINFO fileInfo = {0};
    3. SHGetFileInfo(path,-1,&fileInfo,sizeof(fileInfo),SHGFI_ICON | SHGFI_LARGEICON);
    4.  
    5. *pixmap = QPixmap::fromWinHICON(fileInfo.hIcon);
    To copy to clipboard, switch view to plain text mode 

    That's the way I would think it should work, but it doesn't. The code onse again compiles error-less but as soon as debugger runs through the function I get SIGSEGV, operating system signal inside of QPixmap::fromHIcon().
    I didn't quite get, what you meant with
    so you need to either copy the code and be GPL licensed or write your own version
    . Any further advice?

    Thanks a lot!

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Extracting larger icons

    Since you are using Qt you should be passing a unicode string to SHGetFileInfo, not a LPCTSTR:
    Qt Code:
    1. SHGetFileInfo(QDir::toNativeSeparators(fileName).utf16(), ...
    To copy to clipboard, switch view to plain text mode 
    Secondly, I prefer to grab a handle to the system icon list and then use SYSICONINDEX param to SHGetFileInfo(), but it's your choice.

  5. #5
    Join Date
    Apr 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: Extracting larger icons

    Thanks for your reply, but the code you suggested doesn't seem to work. SHGetFileInfo(), as MSDN says, requires LPCTSTR/ const char*, but your code produces const ushort*:
    Qt Code:
    1. QDir::toNativeSeparators(filePath).utf16()
    To copy to clipboard, switch view to plain text mode 
    These are not compatible and a direct cast won't work either. I really don't know what to do, as just about any modern application wich does a such task is capable of extracting larger icons, I'd never thought that it could be that difficult.

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Extracting larger icons

    If you are using Qt, then you will be using the Unicode libraries, so SHGetFileInfo will be aliased to SHGetFileInfoW, which although the prototype will be LPCTSTR, you can (and should) use a Unicode string provided by utf16()

    Let me dig out an example from one of my apps... [structure and error checking removed]

    Qt Code:
    1. HIMAGELIST ImageList;
    2. HICON WinIcon;
    3.  
    4. ImageList = (HIMAGELIST) SHGetFileInfo((const WCHAR *)QDir::toNativeSeparators(ee->filePath).utf16(), 0, &FileInfo, sizeof(SHFILEINFO), SHGFI_LARGEICON|SHGFI_SYSICONINDEX);
    5.  
    6. WinIcon = ImageList_GetIcon(ImageList, FileInfo.iIcon, ILD_NORMAL);
    To copy to clipboard, switch view to plain text mode 
    Last edited by squidge; 6th May 2010 at 08:18.

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

    MisterIKS (6th May 2010)

  8. #7
    Join Date
    Apr 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: Extracting larger icons

    Thank you so much for that example, I'm confident of it to work fine, but sorry for getting on your nerves, but what do I need to include in order to get this to work? I Included "windows.h" which works fine for SHFILEINFO and HICON but doesn't provide HIMAGELIST.I've googled for it and the second result was this thread itself.

    I'm looking forward to finally getting this to work after endless weeks of trying Once again, thank you!

  9. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Extracting larger icons

    Try CommCtrl.h

  10. #9
    Join Date
    Apr 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: Extracting larger icons

    The output window throughs out the following error:
    undefined reference to `ImageList_GetIcon@12`
    collect2: ld returned 1 exit status
    I've neither seen the first line, nor the second line in this context. "windows.h" and "commctrl.h" are included, I can't see a solution...

  11. #10
    Join Date
    May 2010
    Location
    Germany
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extracting larger icons

    Hi, I am having the same problem. But I know that the WinAPI Method
    Qt Code:
    1. SHGetImageList()
    To copy to clipboard, switch view to plain text mode 
    could do the job. The problem I have is that SHGetImageList is not found in my QtCreator although I include "shellapi.h" which is required according to msdn. Does anybody has some hints for me to get this function working?

  12. #11
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Extracting larger icons

    SHGetImageList is part of Windows SDK 'shellapi.h' header file. Last time I looked it was not supported in MinGW version of 'shellapi.h'.

  13. #12
    Join Date
    May 2010
    Location
    Germany
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extracting larger icons

    Ok, as mingw is opensource is there any way to include this function into the mingw 'shellapi.h' version?

Similar Threads

  1. Combining QT4 with larger C project
    By thuswa in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2009, 01:46
  2. how can I make the Icon larger
    By duduqq in forum Qt Programming
    Replies: 1
    Last Post: 8th July 2008, 02:28
  3. Extracting text from QDomNodes
    By Matt Smith in forum Qt Programming
    Replies: 3
    Last Post: 25th February 2007, 20:27
  4. How to get larger radio buttons on XP?
    By Ben.Hines in forum Qt Programming
    Replies: 9
    Last Post: 24th April 2006, 19:00
  5. Is possible to get QStyle::SP_FileIcon larger?
    By Dark_Tower in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 13:31

Tags for this Thread

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.