View Full Version : Obtaining a Windows file icon using fromWinHBITMAP()

3rd October 2008, 11:17
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:

// fileInfo.hIcon obtained via SHGetFileInfo with flags SHGFI_ICON | SHGFI_SMALLICON
ICONINFO iconInfo;
if ( GetIconInfo(fileInfo.hIcon, &iconInfo) )
QPixmap &iconPixmap = QPixmap::fromWinHBITMAP(

QBitmap iconMaskBitmap(
QPixmap::NoAlpha) );


resultingIcon = QIcon(iconPixmap) ;

3rd October 2008, 11:49
Have you tried with QFileIconProvider?

3rd October 2008, 12:50
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.