Results 1 to 3 of 3

Thread: Obtaining a Windows file icon using fromWinHBITMAP()

  1. #1
    Join Date
    Sep 2008
    Posts
    25
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Obtaining a Windows file icon using fromWinHBITMAP()

    I am getting a Windows file icon via Win Api methods. Then I convert it to QT QIcon and use in my application. Everything seems to be good, but I see a little difference between my icons and those in Windows Explorer(Look at the attached image, left part is my app, right part is Windows Explorer). I think it may be related to shadows or Alpha channel. May be smb can help me to fix this?
    Here is my code for obtaining an icon:

    Qt Code:
    1. // fileInfo.hIcon obtained via SHGetFileInfo with flags SHGFI_ICON | SHGFI_SMALLICON
    2. ICONINFO iconInfo;
    3. if ( GetIconInfo(fileInfo.hIcon, &iconInfo) )
    4. {
    5. QPixmap &iconPixmap = QPixmap::fromWinHBITMAP(
    6. iconInfo.hbmColor,
    7. QPixmap::NoAlpha);
    8.  
    9. QBitmap iconMaskBitmap(
    10. QPixmap::fromWinHBITMAP(iconInfo.hbmMask,
    11. QPixmap::NoAlpha) );
    12.  
    13. iconPixmap.setMask(iconMaskBitmap);
    14.  
    15. resultingIcon = QIcon(iconPixmap) ;
    16. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

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

    Default Re: Obtaining a Windows file icon using fromWinHBITMAP()

    Have you tried with QFileIconProvider?
    J-P Nurmi

  3. #3
    Join Date
    Sep 2008
    Posts
    25
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Obtaining a Windows file icon using fromWinHBITMAP()

    Yes, it does not return a proper file icon.
    I've looked in sources it returns a standard QStyle::SP_FileIcon for all files.
    I'll use it for Windows drives, thanks to you, but the problem is not solved.
    Last edited by DIMEDROLL; 3rd October 2008 at 11:51. Reason: spelling error

Similar Threads

  1. setting main application icon on windows
    By JeanC in forum Qt Programming
    Replies: 7
    Last Post: 12th June 2017, 05:35
  2. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 19:41
  3. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 11:47
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

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.