< Development‎ | Tutorials
Revision as of 12:01, 25 November 2012 by Sassman (Talk | contribs)

Jump to: navigation, search


When you create your own KDE application you will probably want icons in it like this:


These icons are called KIcons. This article shows you how to do this using the software krep as an example. In case of a CMake-based project you will need to

How to use icons in QMake-based projects is discussed elsewhere.

Your KDE project

If you have a KDE project and want to use icons within it, and want these icons installed seamlessly, you will have to name the icons after the project. In the following we look at a project named krep. The important lines in CMakeLists.txt are the ones printed bold below:

PROJECT( krep )
SET( krepSources main.cpp krep.cpp krep.h )
qt4_add_dbus_adaptor( krepSources 
                      MainAdaptor )
kde4_add_ui_files( krepSources krepui.ui )
kde4_add_app_icon( krepSources "hi*-app-krep.png" )
KDE4_ADD_EXECUTABLE( krep ${krepSources} )
kde4_install_icons( ${ICON_INSTALL_DIR} )

Weitere Informationen:

How to test it

  • delete a file
 rm /usr/local/share/icons/hicolor/22x22/apps/krep.png
We are assuming your icon path is /usr/local/share/icons.

Find it out with the command

kde4-config --path icon
  • delete your cache
rm -rf /var/tmp/kdecache-$USER/icon-cache.kcache

According to Development/CMake/Addons_for_KDE#Macros you need to provide a 128x128 pixels icon.

The icon naming scheme

Example for icon names:

  • hisc-apps-bla.svgz will be installed e.g. to /usr/local/share/icons/hicolor/scalable/apps/bla.svgz. hi stands for "hicolor", sc for "scalable", apps for "applications", bla for the application's name and .svgz is the suffix for gzipped scalable vector graphic files.
  • hi128-apps-ktimetracker.png will be installed e.g. to /usr/share/icons/hicolor/128x128/apps/ktimetracker.png. hi stands for "hicolor", 128 for a resolution of 128x128 pixels, apps for "applications", ktimetracker for the application's name and .png is the suffix for portable network graphic files.

example application

In this chapter we will build - on top of the KAction example - an example application kicons that looks like this:


You can obtain its source code as part of kdeexamples by calling

git clone git://


The example application consists of

just taken from the KAction example
Note the command
that sets the icon
just taken from the KAction example
This is a file that defines our icon in (almost natural) english language. It is a scalable vector graphic file. Before being used, it must be converted into a zipped scalable vector graphic named hisc-apps-tutorial-kicon.svgz, see below.
just taken from the KAction example
sorry for the name, but there are naming conventions. Create this file with the convert command from the ImageMagick package
convert world.svg hisc-apps-tutorial-kicon.svgz
Note the commands
which integrate the icons.

build it

To compile, link and install the example application, do a

cmake . && make && make install

To run it, call


Analyzing the KApplications

Maybe you have already searched for yourself how a KDE application finds its icons. You will not be successful like this:

 # [ strace -e open] ktimetracker 2>&1 | grep icon
 open("/usr/lib64/", O_RDONLY) = 3

You see, a KDE application (in this case ktimetracker) does not open icon files or even look for them. However, it spawns a process to look for these icons:

 linux-qgla:~/repos/kdepim/ktimetracker # strace -ffe open ktimetracker 2>&1 | grep icon
 open("/usr/lib64/", O_RDONLY) = 3
 [pid  3457] open("/root/.icons/DMZ/cursors/left_ptr", O_RDONLY) = -1 ENOENT (No such file or directory)
 [pid  3457] open("/root/.icons/DMZ/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
 [pid  3457] open("/usr/share/icons/DMZ/cursors/left_ptr", O_RDONLY) = 10
 [pid  3457] open("/var/tmp/kdecache-root/icon-cache.kcache", O_RDWR|O_CREAT|O_CLOEXEC, 0666) = 10
 [pid  3457] open("/var/tmp/kdecache-root/kpc/", O_RDONLY|O_CLOEXEC) = 10
 [pid  3457] open("/var/tmp/kdecache-root/kpc/kde-icon-cache.index", O_RDONLY|O_CLOEXEC) = 10

Moving On

Now you can move on to how to place your application in the K-Menu using .desktop files.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal