[556] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[556] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
| 8 | **
|
---|
[846] | 9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
[556] | 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
[846] | 13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
| 14 | ** written agreement between you and Nokia.
|
---|
[556] | 15 | **
|
---|
[846] | 16 | ** GNU Free Documentation License
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
| 18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
| 20 | ** file.
|
---|
[556] | 21 | **
|
---|
| 22 | ** If you have questions regarding the use of this file, please contact
|
---|
| 23 | ** Nokia at qt-info@nokia.com.
|
---|
| 24 | ** $QT_END_LICENSE$
|
---|
| 25 | **
|
---|
| 26 | ****************************************************************************/
|
---|
| 27 |
|
---|
| 28 | /*!
|
---|
| 29 | \page appicon.html
|
---|
| 30 | \title Setting the Application Icon
|
---|
[846] | 31 | \brief How to set your application's icon.
|
---|
[556] | 32 |
|
---|
| 33 | \ingroup best-practices
|
---|
| 34 |
|
---|
| 35 | The application icon, typically displayed in the top-left corner of an
|
---|
| 36 | application's top-level windows, is set by calling the
|
---|
| 37 | QWidget::setWindowIcon() method on top-level widgets.
|
---|
| 38 |
|
---|
| 39 | In order to change the icon of the executable application file
|
---|
| 40 | itself, as it is presented on the desktop (i.e., prior to
|
---|
| 41 | application execution), it is necessary to employ another,
|
---|
| 42 | platform-dependent technique.
|
---|
| 43 |
|
---|
| 44 | \tableofcontents
|
---|
| 45 |
|
---|
| 46 | \section1 Setting the Application Icon on Windows
|
---|
| 47 |
|
---|
| 48 | First, create an ICO format bitmap file that contains the icon
|
---|
| 49 | image. This can be done with e.g. Microsoft Visual C++: Select
|
---|
| 50 | \menu{File|New}, then select the \menu{File} tab in the dialog
|
---|
| 51 | that appears, and choose \menu{Icon}. (Note that you do not need
|
---|
| 52 | to load your application into Visual C++; here we are only using
|
---|
| 53 | the icon editor.)
|
---|
| 54 |
|
---|
| 55 | Store the ICO file in your application's source code directory,
|
---|
| 56 | for example, with the name \c myappico.ico. Then, create a text
|
---|
| 57 | file called, say, \c myapp.rc in which you put a single line of
|
---|
| 58 | text:
|
---|
| 59 |
|
---|
| 60 | \snippet doc/src/snippets/code/doc_src_appicon.qdoc 0
|
---|
| 61 |
|
---|
| 62 | Finally, assuming you are using \c qmake to generate your
|
---|
| 63 | makefiles, add this line to your \c myapp.pro file:
|
---|
| 64 |
|
---|
| 65 | \snippet doc/src/snippets/code/doc_src_appicon.qdoc 1
|
---|
| 66 |
|
---|
| 67 | Regenerate your makefile and your application. The \c .exe file
|
---|
| 68 | will now be represented with your icon in Explorer.
|
---|
| 69 |
|
---|
| 70 | If you do not use \c qmake, the necessary steps are: first, run
|
---|
| 71 | the \c rc program on the \c .rc file, then link your application
|
---|
| 72 | with the resulting \c .res file.
|
---|
| 73 |
|
---|
| 74 | \section1 Setting the Application Icon on Mac OS X
|
---|
| 75 |
|
---|
| 76 | The application icon, typically displayed in the application dock
|
---|
| 77 | area, is set by calling QWidget::setWindowIcon() on a top-level
|
---|
| 78 | widget. It is possible that the program could appear in the
|
---|
| 79 | application dock area before the function call, in which case a
|
---|
| 80 | default icon will appear during the bouncing animation.
|
---|
| 81 |
|
---|
| 82 | To ensure that the correct icon appears, both when the application is
|
---|
| 83 | being launched, and in the Finder, it is necessary to employ a
|
---|
| 84 | platform-dependent technique.
|
---|
| 85 |
|
---|
| 86 | Although many programs can create icon files (\c .icns), the
|
---|
| 87 | recommended approach is to use the \e{Icon Composer} program
|
---|
| 88 | supplied by Apple (in the \c Developer/Application folder).
|
---|
| 89 | \e{Icon Composer} allows you to import several different sized
|
---|
| 90 | icons (for use in different contexts) as well as the masks that
|
---|
| 91 | go with them. Save the set of icons to a file in your project
|
---|
| 92 | directory.
|
---|
| 93 |
|
---|
| 94 | If you are using qmake to generate your makefiles, you only need
|
---|
| 95 | to add a single line to your \c .pro project file. For example,
|
---|
| 96 | if the name of your icon file is \c{myapp.icns}, and your project
|
---|
| 97 | file is \c{myapp.pro}, add this line to \c{myapp.pro}:
|
---|
| 98 |
|
---|
| 99 | \snippet doc/src/snippets/code/doc_src_appicon.qdoc 2
|
---|
| 100 |
|
---|
| 101 | This will ensure that \c qmake puts your icons in the proper
|
---|
| 102 | place and creates an \c{Info.plist} entry for the icon.
|
---|
| 103 |
|
---|
| 104 | If you do not use \c qmake, you must do the following manually:
|
---|
| 105 | \list 1
|
---|
| 106 | \i Create an \c Info.plist file for your application (using the
|
---|
| 107 | \c PropertyListEditor, found in \c Developer/Applications).
|
---|
| 108 | \i Associate your \c .icns record with the \c CFBundleIconFile record in the
|
---|
| 109 | \c Info.plist file (again, using the \c PropertyListEditor).
|
---|
| 110 | \i Copy the \c Info.plist file into your application bundle's \c Contents
|
---|
| 111 | directory.
|
---|
| 112 | \i Copy the \c .icns file into your application bundle's \c Contents/Resources
|
---|
| 113 | directory.
|
---|
| 114 | \endlist
|
---|
| 115 |
|
---|
| 116 | \section1 Setting the Application Icon on Common Linux Desktops
|
---|
| 117 |
|
---|
| 118 | In this section we briefly describe the issues involved in providing
|
---|
| 119 | icons for applications for two common Linux desktop environments:
|
---|
| 120 | \l{http://www.kde.org/}{KDE} and \l{http://www.gnome.org/}{GNOME}.
|
---|
| 121 | The core technology used to describe application icons
|
---|
| 122 | is the same for both desktops, and may also apply to others, but there
|
---|
| 123 | are details which are specific to each. The main source of information
|
---|
| 124 | on the standards used by these Linux desktops is
|
---|
| 125 | \l{http://www.freedesktop.org/}{freedesktop.org}. For information
|
---|
| 126 | on other Linux desktops please refer to the documentation for the
|
---|
| 127 | desktops you are interested in.
|
---|
| 128 |
|
---|
| 129 | Often, users do not use executable files directly, but instead launch
|
---|
| 130 | applications by clicking icons on the desktop. These icons are
|
---|
| 131 | representations of "desktop entry files" that contain a description of
|
---|
| 132 | the application that includes information about its icon. Both desktop
|
---|
| 133 | environments are able to retrieve the information in these files, and
|
---|
| 134 | they use it to generate shortcuts to applications on the desktop, in
|
---|
| 135 | the start menu, and on the panel.
|
---|
| 136 |
|
---|
| 137 | More information about desktop entry files can be found in the
|
---|
| 138 | \l{http://www.freedesktop.org/Standards/desktop-entry-spec}{Desktop Entry
|
---|
| 139 | Specification}.
|
---|
| 140 |
|
---|
| 141 | Although desktop entry files can usefully encapsulate the application's details,
|
---|
| 142 | we still need to store the icons in the conventional location for each desktop
|
---|
| 143 | environment. A number of locations for icons are given in the
|
---|
| 144 | \l{http://www.freedesktop.org/Standards/icon-theme-spec}{Icon Theme
|
---|
| 145 | Specification}.
|
---|
| 146 |
|
---|
| 147 | Although the path used to locate icons depends on the desktop in use,
|
---|
| 148 | and on its configuration, the directory structure beneath each of
|
---|
| 149 | these should follow the same pattern: subdirectories are arranged by
|
---|
| 150 | theme, icon size, and application type. Generally, application icons
|
---|
| 151 | are added to the hicolor theme, so a square application icon 32 pixels
|
---|
| 152 | in size would be stored in the \c hicolor/32x32/apps directory beneath
|
---|
| 153 | the icon path.
|
---|
| 154 |
|
---|
| 155 | \section2 K Desktop Environment (KDE)
|
---|
| 156 |
|
---|
| 157 | Application icons can be installed for use by all users, or on a per-user basis.
|
---|
| 158 | A user currently logged into their KDE desktop can discover these locations
|
---|
| 159 | by using \l{http://developer.kde.org/documentation/other/kde-config.html}{kde-config},
|
---|
| 160 | for example, by typing the following in a terminal window:
|
---|
| 161 |
|
---|
| 162 | \snippet doc/src/snippets/code/doc_src_appicon.qdoc 3
|
---|
| 163 |
|
---|
| 164 | Typically, the list of colon-separated paths printed to stdout includes the
|
---|
| 165 | user-specific icon path and the system-wide path. Beneath these
|
---|
| 166 | directories, it should be possible to locate and install icons according
|
---|
| 167 | to the conventions described in the
|
---|
| 168 | \l{http://www.freedesktop.org/Standards/icon-theme-spec}{Icon Theme Specification}.
|
---|
| 169 |
|
---|
| 170 | If you are developing exclusively for KDE, you may wish to take
|
---|
| 171 | advantage of the \link
|
---|
| 172 | http://developer.kde.org/documentation/other/makefile_am_howto.html
|
---|
| 173 | KDE build system\endlink to configure your application. This ensures
|
---|
| 174 | that your icons are installed in the appropriate locations for KDE.
|
---|
| 175 |
|
---|
| 176 | The KDE developer website is at \l{http://developer.kde.org/}.
|
---|
| 177 |
|
---|
| 178 | \section2 GNOME
|
---|
| 179 |
|
---|
| 180 | Application icons are stored within a standard system-wide
|
---|
| 181 | directory containing architecture-independent files. This
|
---|
| 182 | location can be determined by using \c gnome-config, for example
|
---|
| 183 | by typing the following in a terminal window:
|
---|
| 184 |
|
---|
| 185 | \snippet doc/src/snippets/code/doc_src_appicon.qdoc 4
|
---|
| 186 |
|
---|
| 187 | The path printed on stdout refers to a location that should contain a directory
|
---|
| 188 | called \c{pixmaps}; the directory structure within the \c pixmaps
|
---|
| 189 | directory is described in the \link
|
---|
| 190 | http://www.freedesktop.org/Standards/icon-theme-spec Icon Theme
|
---|
| 191 | Specification \endlink.
|
---|
| 192 |
|
---|
| 193 | If you are developing exclusively for GNOME, you may wish to use
|
---|
| 194 | the standard set of \link
|
---|
| 195 | http://developer.gnome.org/tools/build.html GNU Build Tools\endlink,
|
---|
| 196 | also described in the relevant section of
|
---|
| 197 | the \link http://developer.gnome.org/doc/GGAD/ggad.html GTK+/Gnome
|
---|
| 198 | Application Development book\endlink. This ensures that your icons are
|
---|
| 199 | installed in the appropriate locations for GNOME.
|
---|
| 200 |
|
---|
| 201 | The GNOME developer website is at \l{http://developer.gnome.org/}.
|
---|
| 202 |
|
---|
| 203 | \section1 Setting the Application Icon on the Symbian platform
|
---|
| 204 |
|
---|
| 205 | In order to set the application icon for Symbian platform applications, you need
|
---|
| 206 | an SVG-T icon. For information on how to create SVG-T compliant icons,
|
---|
| 207 | please refer to
|
---|
| 208 | \l{http://wiki.forum.nokia.com/index.php/How_to_create_application_icon(SVG)_in_S60_3rd_edition/}
|
---|
| 209 |
|
---|
| 210 | Once the icon is available in the correct format and assuming you are
|
---|
| 211 | using \c qmake to generate your makefiles, you only need to add a single
|
---|
| 212 | line to your \c .pro project file. For example, if the name of your
|
---|
| 213 | icon file is \c{myapp.svg}, and your project file is \c{myapp.pro},
|
---|
| 214 | add this line to \c{myapp.pro}:
|
---|
| 215 |
|
---|
| 216 | \snippet doc/src/snippets/code/doc_src_appicon.qdoc 5
|
---|
| 217 |
|
---|
| 218 | */
|
---|