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