Skip to content

Setting the Application Icon

Radhi edited this page Aug 12, 2017 · 6 revisions

The application icon, which typically displayed in the top-left corner of an application, can be set by calling the SetIcon() method in the main window of your app. However, in order to change the icon of the executable file itself (i.e., prior to application execution), it is necessary to employ another, platform-dependent technique.

Platforms

Setting the Icon on Windows

  1. Make sure you have an ICO format bitmap file that contains the icon image for your app.

  2. Store the ICO file in your project's root directory, for example, with the name myicon.ico.

  3. Create a file called icon.rc with the following content in your root project directory :

    IDI_ICON1 ICON DISCARDABLE "myicon.ico"
    
  4. Open terminal inside your project directory, then run windres like this :

    path/to/windres icon.rc -o icon_windows.syso
    

    In Windows system, windres usually can be found inside the same folder as rcc, for example in Qt5.8.0/5.8/mingw53_32/bin/windres.exe. In Linux, you have to install mingw-w64 first using your package manager. Once installled, you can run windres either by calling i686-w64-mingw32-windres (if you deploying for Windows 32-bit) or x86_64-w64-mingw32-windres (if you deploying for Windows 64-bit).

    At this point, your project directory should look like this :

    project_name
    ├── icon.rc
    ├── icon_windows.syso
    ├── myicon.ico
    └── project.go
    
  5. Deploy your app like usual, the *.syso file should be automatically detected and be added to your binary.

Setting the Icon on macOS

  1. Make sure you have an icon files (.icns) that contains the icon image for your app. Although many programs can create icns files, the recommended approach is to use the iconutil program supplied by Apple. iconutil is a command-line tool that converts iconset folders to deployment-ready, high-resolution icns files. Using this tool also compresses the resulting icns file, so there is no need for you to perform additional compression.

  2. Copy your icns file to project-directory/darwin/Contents/Resources, for example, with the name project_name.icns.

  3. Open or create Info.plist file which located in project-directory/darwin/Contents/Info.plist.

  4. Associate your project_name.icns record with the CFBundleIconFile record in the Info.plist. At this point, your project directory should look like this :

    project_name
    ├── darwin
    │   └── Contents
    │       ├── Info.plist
    │       └── Resources
    │           └── project_name.icns
    └── project.go
    
  5. Deploy your app like usual.

Setting the Icon on Linux

Executable files on Linux do not have icons embedded in itself. Instead, the icons is displayed on Desktop Entry files that contain a description of the application that includes information about its icon. For more details, you can check the Arch wiki.

Setting the Icon on Android

Just like other Android project, you can set the application icon by modifying AndroidManifest.xml file. Using this binding, the manifest file will be located under android or android-emulator folder at the root of your project :

project_name
├── android
│   ├── AndroidManifest.xml
│   ├── alias.txt
│   ├── build.gradle
│   ├── gradle
│   │   └── wrapper
│   │       └── gradle-wrapper.properties
│   ├── icon.png
│   ├── password.txt
│   ├── project_name.keystore
│   └── res
│       ├── drawable-hdpi
│       │   └── icon.png
│       ├── drawable-ldpi
│       │   └── icon.png
│       └── drawable-mdpi
│           └── icon.png
└── project.go

Setting the Icon on SailfishOS

To set the icon, you can use the *.desktop and *.spec files, which located inside sailfish or sailfish-emulator folder at the root of your project, as a template to build upon :

project_name
├── project.go
└── sailfish
    ├── harbour-project_name.png
    ├── project_name.desktop
    └── project_name.spec
Clone this wiki locally