Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get default app icon on Windows
Forum Updated to NodeBB v4.3 + New Features

Get default app icon on Windows

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by Cobra91151
    #1

    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.

    K 1 Reply Last reply
    0
    • Cobra91151C Cobra91151

      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.

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @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.

      Vote the answer(s) that helped you to solve your issue(s)

      Cobra91151C 1 Reply Last reply
      0
      • K koahnig

        @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.

        Cobra91151C Offline
        Cobra91151C Offline
        Cobra91151
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • Cobra91151C Offline
          Cobra91151C Offline
          Cobra91151
          wrote on last edited by Cobra91151
          #4

          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.

          1 Reply Last reply
          0
          • hskoglundH Offline
            hskoglundH Offline
            hskoglund
            wrote on last edited by hskoglund
            #5

            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"

            Cobra91151C 1 Reply Last reply
            1
            • hskoglundH hskoglund

              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"

              Cobra91151C Offline
              Cobra91151C Offline
              Cobra91151
              wrote on last edited by
              #6

              @hskoglund

              It works. Thanks.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved