Qt-interest Archive, July 2007
how to convert a HICON to QIcon (Win32)
Message 1 in thread
Hi people,
I'm writing a small application, I need a QTreeView to show some tree,
and the decoration of each item is come from system, which is got from
SHGetFileInfo.
Since there is no way to convert the HICON to QIcon/QPixmap directly, so
I have to use the GetIconInfo function to get the data of HICON, this
ICONINFO have 2 members, one is color, another is alpha/mask.
So, here comes a problem, the Icon from SHGetFileInfo can have a alpha
channel, if I use these code to convert:
QIcon icon(QPixmap::fromWinHBITMAP(iconInfo.hbmColor,
QPixmap::PremultipliedAlpha));
the result icon will lost alpha channel, or alpha channel will blend
incorrectly.
If I use the hbmMask member of ICONINFO to set the alpha channel, the result
is still incorrect.
How can I convert a HICON to QIcon/QPixmap with alpha correctly
preserved?
--
[ signature omitted ]
Message 2 in thread
Im not in front of a QT code base right now, but I believe the QDirModel
win32 portions use the system HICON info to do just this... I may be
mistaken.
Scott
> -----Original Message-----
> From: Steve Yin [mailto:steve@xxxxxxxxxxxx]
> Sent: Thursday, July 05, 2007 11:19 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: how to convert a HICON to QIcon (Win32)
>
> Hi people,
> I'm writing a small application, I need a QTreeView to show some
tree,
> and the decoration of each item is come from system, which is got from
> SHGetFileInfo.
> Since there is no way to convert the HICON to QIcon/QPixmap
directly,
> so
> I have to use the GetIconInfo function to get the data of HICON, this
> ICONINFO have 2 members, one is color, another is alpha/mask.
> So, here comes a problem, the Icon from SHGetFileInfo can have a
alpha
> channel, if I use these code to convert:
> QIcon icon(QPixmap::fromWinHBITMAP(iconInfo.hbmColor,
> QPixmap::PremultipliedAlpha));
> the result icon will lost alpha channel, or alpha channel will blend
> incorrectly.
> If I use the hbmMask member of ICONINFO to set the alpha channel, the
> result
> is still incorrect.
>
> How can I convert a HICON to QIcon/QPixmap with alpha correctly
> preserved?
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 3 in thread
well, thanks!! I found this function convertHIconToPixmap in
qpixmap_win.cpp. it's not exported, so I just copy this function to my
source.
I'm wondering why this is not a member function of QPixmap. :(
Thanks again :)
"Scott Aron Bloom" <scott@xxxxxxxxxxxx> ååææ
news:E2E5EA152B64E044B464DA705AF44AAE04F762@xxxxxxxxxxxxxxxxxxxxxx
Im not in front of a QT code base right now, but I believe the QDirModel
win32 portions use the system HICON info to do just this... I may be
mistaken.
Scott
> -----Original Message-----
> From: Steve Yin [mailto:steve@xxxxxxxxxxxx]
> Sent: Thursday, July 05, 2007 11:19 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: how to convert a HICON to QIcon (Win32)
>
> Hi people,
> I'm writing a small application, I need a QTreeView to show some
tree,
> and the decoration of each item is come from system, which is got from
> SHGetFileInfo.
> Since there is no way to convert the HICON to QIcon/QPixmap
directly,
> so
> I have to use the GetIconInfo function to get the data of HICON, this
> ICONINFO have 2 members, one is color, another is alpha/mask.
> So, here comes a problem, the Icon from SHGetFileInfo can have a
alpha
> channel, if I use these code to convert:
> QIcon icon(QPixmap::fromWinHBITMAP(iconInfo.hbmColor,
> QPixmap::PremultipliedAlpha));
> the result icon will lost alpha channel, or alpha channel will blend
> incorrectly.
> If I use the hbmMask member of ICONINFO to set the alpha channel, the
> result
> is still incorrect.
>
> How can I convert a HICON to QIcon/QPixmap with alpha correctly
> preserved?
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 4 in thread
Steve Yin schrieb:
> ...
> I'm wondering why this is not a member function of QPixmap. :(
Because it's platform-dependent and not of much interest, I guess ;)
Cheers, Oliver
--
[ signature omitted ]
Message 5 in thread
Steve,
You can do it like this:
HICON icon;
ICONINFO info;
bool const b = ::GetIconInfo( icon, &info );
QPixmap pixmap = QPixmap::fromWinHBITMAP( info.hbmColor, QPixmap::NoAlpha );
::DeleteObject( info.hbmColor );
::DeleteObject( info.hbmMask );
::DestroyIcon( icon );
Yuriy
"Steve Yin" <steve@xxxxxxxxxxxx> §ã§à§à§Ò§ë§Ú§Ý/§ã§à§à§Ò§ë§Ú§Ý§Ñ §Ó
§ß§à§Ó§à§ã§ä§ñ§ç §ã§Ý§Ö§Õ§å§ð§ë§Ö§Ö: news:f6kmt1$bpa$1@xxxxxxxxxxxxxxxxxxxxx
> Hi people,
> I'm writing a small application, I need a QTreeView to show some tree,
> and the decoration of each item is come from system, which is got from
> SHGetFileInfo.
> Since there is no way to convert the HICON to QIcon/QPixmap directly,
> so I have to use the GetIconInfo function to get the data of HICON, this
> ICONINFO have 2 members, one is color, another is alpha/mask.
> So, here comes a problem, the Icon from SHGetFileInfo can have a alpha
> channel, if I use these code to convert:
> QIcon icon(QPixmap::fromWinHBITMAP(iconInfo.hbmColor,
> QPixmap::PremultipliedAlpha));
> the result icon will lost alpha channel, or alpha channel will blend
> incorrectly.
> If I use the hbmMask member of ICONINFO to set the alpha channel, the
> result is still incorrect.
>
> How can I convert a HICON to QIcon/QPixmap with alpha correctly
> preserved?
--
[ signature omitted ]