Qt 如何获取一个文件的 Icon 图标?
#include <QPixmap>
#include <QString>
#include <QFileInfo>
#include <QFileIconProvider>
#include <QtWinExtras/QtWinExtras>
static QPixmap GetFileIcon(QString path,QString savePath)
{
QFileInfo fileInfo(path);
QFileIconProvider icon;
QPixmap pixmap = icon.icon(fileInfo).pixmap(32,32);
pixmap.save(savePath);
return pixmap;
}
static QPixmap GetFileIconEx(QString path,QString savePath)
{
Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon);
SHFILEINFOA psfi;
SHGetFileInfoA(path.toStdString().c_str(),NULL,&psfi,sizeof(SHFILEINFOA),SHGFI_ICON);
QPixmap pixmap = qt_pixmapFromWinHICON(psfi.hIcon);
pixmap.save(savePath);
DestroyIcon(psfi.hIcon);
return pixmap;
}
转载请注明出处并保持作品的完整性,谢谢