Setting the Application Icon - therecipe/qt GitHub Wiki

The application icon, which is typically displayed in the top-left corner of an application, can be set by calling the SetIcon() method of the main window of your application.

However, in order to change the icon of the executable file itself (i.e. prior the application execution), it is necessary to employ additional platform-dependent techniques.

Platforms

Windows

  • Make sure you have an ICO format bitmap file that contains the icon image for your app.
  • Store the ICO file in the root folder of your project, for example with the name icon.ico.
  • Create a file called icon.rc alongside the icon.ico with the following content:
IDI_ICON1 ICON DISCARDABLE "icon.ico"
  • Open the terminal inside your project folder and run windres like this:
path/to/windres icon.rc -o icon_windows.syso

On Windows, you can usually find windres in the same folder as rcc, for example in path/to/Qt/5.13/mingw73_64/bin/windres.exe.

On Linux, you have to install mingw-w64 using your package manager. Once installed, you can run windres either by calling i686-w64-mingw32-windres (for 32 bit deployments) or x86_64-w64-mingw32-windres (for 64 bit deployment).

If you have MXE installed, then you can also find windres under /usr/lib/mxe/usr/bin/, either called i686-w64-mingw32.{shared|static}-windres (for 32 bit deployments) or x86_64-w64-mingw32.{shared|static}-windres (for 64 bit deployment).

There is an application rsrc, that can aid you in creating the syso file. It's been tested on Mac OSX to create the Windows syso file using the following flags, however therecipe doesn't offer support around this tool if you use it.

rsrc -ico icon.ico -o icon.syso -arch=amd64

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

project_name
├── icon.ico
├── icon.rc
├── icon_windows.syso
└── main.go
  • Now deploy your application as usual, the *.syso file should be automatically detected and be added to your binary.

You can find a working example here

macOS

  • 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.
  • Copy your icns file to project_name/darwin/Contents/Resources, for example, with the name project_name.icns.
  • Open or create the Info.plist file which is located in project_name/darwin/Contents/Info.plist.
  • Associate your project_name.icns record with the CFBundleIconFile record in the Info.plist.

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

project_name
├── darwin
│   └── Contents
│       ├── Info.plist
│       └── Resources
│           └── project_name.icns
└── main.go
  • Now deploy your application with qtdeploy as usual.

You can find a working example here

Linux

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

You can find an example which is in the works here

Android

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

To do so, you just need to structure your project like this:

project_name
├── android
│   ├── AndroidManifest.xml
│   ├── project_name.jks
│   ├── jks_alias
│   ├── jks_pass
│   └── res
│       ├── drawable-hdpi
│       │   └── ic_launcher.png
│       ├── drawable-mdpi
│       │   └── ic_launcher.png
│       ├── drawable-xhdpi
│       │   └── ic_launcher.png
│       ├── drawable-xxhdpi
│       │   └── ic_launcher.png
│       └── drawable-xxxhdpi
│           └── ic_launcher.png
├── android-emulator -> ./android/
└── main.go

Then deploy your application with qtdeploy as usual.

You can find a working example here

iOS

Just like any other iOS project, you can set the application icon by using appiconsets.

To do so, you just need to structure your project like this:

project_name
├── ios
│   ├── Images.xcassets
│   │   └── AppIcon.appiconset
│   │       ├── 1024.png
│   │       ├── 120.png
│   │       ├── 121.png
│   │       ├── 152.png
│   │       ├── 167.png
│   │       ├── 180.png
│   │       ├── 20.png
│   │       ├── 31.png
│   │       ├── 40.png
│   │       ├── 41.png
│   │       ├── 42.png
│   │       ├── 58.png
│   │       ├── 59.png
│   │       ├── 61.png
│   │       ├── 76.png
│   │       ├── 80.png
│   │       ├── 81.png
│   │       ├── 87.png
│   │       └── Contents.json
│   └── Info.plist
├── ios-simulator -> ./ios
└── main.go

And deploy your application with qtdeploy as usual.

You can find a working example here

SailfishOS

To set the icon, you can use the *.desktop and *.spec files, which should be located inside the sailfish or sailfish-emulator folder at the root folder of your project:

project_name
├── main.go
├── qml
│   └── main.qml
├── sailfish
│   ├── harbour-project_name.png
│   ├── project_name.desktop
│   └── project_name.spec
└── sailfish-emulator -> ./sailfish/

Then deploy your application with qtdeploy as usual.

You can find a working example here

Ubuntu Touch

To set the icon, you can use the *.desktop and *.apparmor files, which should be located inside the ubports folder at the root folder of your project:

project_name
├── main.go
├── main_vivid.go
├── main_xenial.go
├── qml
│   └── main.qml
└── ubports
    ├── manifest.json
    ├── project_name.apparmor
    └── project_name.desktop

Then deploy your application with qtdeploy as usual.

You can find a working example here