Get default app icon on Windows



  • Hi! I want to get default application icon from QFileIconProvider but there are only:

    enum QFileIconProvider::IconType

    QFileIconProvider::Computer
    QFileIconProvider::Desktop	
    QFileIconProvider::Trashcan	
    QFileIconProvider::Network	
    QFileIconProvider::Drive	
    QFileIconProvider::Folder	
    QFileIconProvider::File
    

    Screenshot:
    alt text

    I can navigate to some system executable file without icon to get this default icon using QFileIconProvider, but I think there should be another approach.
    How to get this icon? Thanks.

    Update:
    I have found the identifier of default app icon - IDI_APPLICATION. The problem now is how to convert it to QIcon or QString? I have tried QString::fromWCharArray(IDI_APPLICATION) and QString::fromStdWString(IDI_APPLICATION) but it doesn't work, the app crashes. How to convert it? Thanks.


  • Moderators

    @Cobra91151

    Did you see this section already?

    The detailed description of QFileIconProvider says:
    The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes.

    Does not seem to be what you require, if I understand you correctly.



  • @koahnig

    This is not what I'm looking for. I need to apply this default icon for another apps (or for example set this default icon on QPushButton) using setIcon function. I need a handle to Windows default app icon.



  • I have found the identifier of default app icon - IDI_APPLICATION. The problem now is how to convert it to QIcon or QString? I have tried QString::fromWCharArray(IDI_APPLICATION) and QString::fromStdWString(IDI_APPLICATION) but it doesn't work, the app crashes. How to convert it? Thanks.



  • Hi, try (assuming you want to show the icon in a QLabel):

    ui->label->setPixmap(QtWin::fromHICON(LoadIcon(NULL,IDI_APPLICATION)));
    

    Note: you need to add LIBS += -luser32 to your .pro file and #include "QtWinExtras"



  • @hskoglund

    It works. Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.