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;
}
posted @ 2018-06-15 09:56  學海無涯  阅读(2682)  评论(0编辑  收藏  举报