Qt 4.8: Application Icon Example

Qt Reference Documentation

- Qt 4.8
- ALL VERSIONS

- A
- A
- A
- Print

# Application Icon Example

Files:

- widgets/applicationicon/applicationicon.svg
- widgets/applicationicon/main.cpp
- widgets/applicationicon/applicationicon.pro

The Application Icon example shows how to add an application icon to a mobile application.

## Creating an icon for Maemo

Maemo expects the icon of an application to be a 64x64 PNG image file. The file name of the icon should be the same as the executable with a `.png` extension. You also need a `.desktop` file that gives the window manager hints about the application, such as name, type and icon.

     [Desktop Entry]
     Encoding=UTF-8
     Version=1.0
     Type=Application
     Terminal=false
     Name=Application Icon
     Exec=/opt/usr/bin/applicationicon
     Icon=applicationicon
     X-Window-Icon=
     X-HildonDesk-ShowInToolbar=true
     X-Osso-Type=application/x-executable

The `Icon` field should also contain the name of the executable. On the device, application icons are stored in the `/usr/share/icons/hicolor/64x64/apps` directory and desktop files in the `/usr/share/applications/hildon` directory.

## Creating an icon for Symbian

Symbian uses Scalable Vector Graphics (SVG Tiny 1.1+) to render application icons in the application menu. Therefore icons could be created manually with a text editor, since SVG files are plain text with XML syntax, but usually you would use a vector graphics program that is able to output SVG files. Popular graphics programs such as Adobe Illustrator or Inkscape are able to do so.

For best results, the icon should be created on a 44x44 pixel canvas. Otherwise the image might be scaled in unexpected ways.

Once you have created your icon, make sure that it is stored according to the SVG-Tiny 1.1+ standard. Inkscape, for instance, is not able to save images that way, but there are tools that can convert general SVG files into the Tiny format. For instance, the svg2svgt tool that is bundled with Symbian 3rd and 5th editon SDKs under the folder s60tools can do this conversion to some extent. Another tool to convert SVG to SVG Tiny is SVG Pony.

## Adding the icons to the project

Edit the .pro file and specify the ICON variable for the symbian target. For Maemo, we need to add that the `.desktop` and icon file should be installed.

     QT       += core gui

     TARGET = applicationicon
     TEMPLATE = app

     SOURCES += main.cpp

     OTHER_FILES += applicationicon.svg \
                    applicationicon.png \
                    applicationicon.desktop

     symbian {
         include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
         # override icon
         ICON = applicationicon.svg
         TARGET.UID3 = 0xe9f919ee
         TARGET.EPOCSTACKSIZE = 0x14000
         TARGET.EPOCHEAPSIZE = 0x020000 0x800000
     }

     maemo5 {
         include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri)

         # override icon from maemo5pkgrules.pri
         icon.files = $${TARGET}.png
     }
     symbian: warning(This example might not fully work on Symbian platform)
     maemo5: warning(This example might not fully work on Maemo platform)
     simulator: warning(This example might not fully work on Simulator platform)

Currently, Qt Creator doesn't include the icon and desktop files in the application package for Maemo, merely the executable file is included. As a workaround for this, the files can be added manually in the Projects tab. In the "Create Package" build step for the Maemo target, the `.desktop` file and icon can be added to be a part of the package contents. Unfortunately, these additions are only stored as a part of the `.pro.user` file. This issue will be resolved in a future release of Qt Creator.