Sophie

Sophie

distrib > Mageia > 6 > i586 > by-pkgid > f93881942bd3805980c2fe63aa853d78 > files > 17

qtdoc5-5.9.4-1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- appicon.qdoc -->
  <title>Setting the Application Icon | Qt 5.9</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.9</a></td><td ><a href="overviews-main.html#best-practices">Best Practice Guides</a></td><td >Setting the Application Icon</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#setting-the-application-icon-on-windows">Setting the Application Icon on Windows</a></li>
<li class="level1"><a href="#setting-the-application-icon-on-macos">Setting the Application Icon on macOS</a></li>
<li class="level1"><a href="#setting-the-application-icon-on-common-linux-desktops">Setting the Application Icon on Common Linux Desktops</a></li>
<li class="level2"><a href="#k-desktop-environment-kde">K Desktop Environment (KDE)</a></li>
<li class="level2"><a href="#gnome">GNOME</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Setting the Application Icon</h1>
<span class="subtitle"></span>
<!-- $$$appicon.html-description -->
<div class="descr"> <a name="details"></a>
<p>The application icon, typically displayed in the top-left corner of an application's top-level windows, is set by calling the QWindow::setIcon() method.</p>
<p>In order to change the icon of the executable application file itself, as it is presented on the desktop (i.e&#x2e;, prior to application execution), it is necessary to employ another, platform-dependent technique.</p>
<a name="setting-the-application-icon-on-windows"></a>
<h2 id="setting-the-application-icon-on-windows">Setting the Application Icon on Windows</h2>
<p>First, create an ICO format bitmap file that contains the icon image. This can be done with e.g&#x2e; Microsoft Visual C++: Select <b>File|New</b>, then select the <b>File</b> tab in the dialog that appears, and choose <b>Icon</b>. (Note that you do not need to load your application into Visual C++; here we are only using the icon editor.)</p>
<p>Store the ICO file in your application's source code directory, for example, with the name <code>myappico.ico</code>.</p>
<p>Then, assuming you are using qmake to generate your makefiles, you only need to add a single line to your <code>.pro</code> project file:</p>
<pre class="cpp">

  RC_ICONS = myappico.ico

</pre>
<p>Finally, regenerate your makefile and your application. The <code>.exe</code> file will now be represented by your icon in Explorer.</p>
<p>However, if you already have an <code>.rc</code> file, for example, with the name <code>myapp.rc</code>, which you want to reuse, the following two steps will be required. First, put a single line of text to the <code>myapp.rc</code> file:</p>
<pre class="cpp">

  IDI_ICON1               ICON    DISCARDABLE     <span class="string">&quot;myappico.ico&quot;</span>

</pre>
<p>Then, add this line to your <code>myapp.pro</code> file:</p>
<pre class="cpp">

  RC_FILE = myapp.rc

</pre>
<p>If you do not use <code>qmake</code>, the necessary steps are: first, create an <code>.rc</code> file and run the <code>rc</code> or <code>windres</code> program on the <code>.rc</code> file, then link your application with the resulting <code>.res</code> file.</p>
<a name="setting-the-application-icon-on-macos"></a>
<h2 id="setting-the-application-icon-on-macos">Setting the Application Icon on macOS</h2>
<p>The application icon, typically displayed in the application dock area, is set by calling QWindow::setWindowIcon() on a window. It is possible that the program could appear in the application dock area before the function call, in which case a default icon will appear during the bouncing animation.</p>
<p>To ensure that the correct icon appears, both when the application is being launched, and in the Finder, it is necessary to employ a platform-dependent technique.</p>
<p>Although many programs can create icon files (<code>.icns</code>), the recommended approach is to use the <i>iconutil</i> program supplied by Apple. <i>iconutil</i> 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.</p>
<p>If you are using qmake to generate your makefiles, you only need to add a single line to your <code>.pro</code> project file. For example, if the name of your icon file is <code>myapp.icns</code>, and your project file is <code>myapp.pro</code>, add this line to <code>myapp.pro</code>:</p>
<pre class="cpp">

  ICON = myapp.icns

</pre>
<p>This will ensure that <code>qmake</code> puts your icons in the proper place and creates an <code>Info.plist</code> entry for the icon.</p>
<p>If you do not use <code>qmake</code>, you must do the following manually:</p>
<ol class="1" type="1"><li>Create an <code>Info.plist</code> file for your application (using the <code>PropertyListEditor</code>, found in <code>Developer/Applications</code>).</li>
<li>Associate your <code>.icns</code> record with the <code>CFBundleIconFile</code> record in the <code>Info.plist</code> file (again, using the <code>PropertyListEditor</code>).</li>
<li>Copy the <code>Info.plist</code> file into your application bundle's <code>Contents</code> directory.</li>
<li>Copy the <code>.icns</code> file into your application bundle's <code>Contents/Resources</code> directory.</li>
</ol>
<a name="setting-the-application-icon-on-common-linux-desktops"></a>
<h2 id="setting-the-application-icon-on-common-linux-desktops">Setting the Application Icon on Common Linux Desktops</h2>
<p>In this section we briefly describe the issues involved in providing icons for applications for two common Linux desktop environments: <a href="http://www.kde.org/">KDE</a> and <a href="http://www.gnome.org/">GNOME</a>. The core technology used to describe application icons is the same for both desktops, and may also apply to others, but there are details which are specific to each. The main source of information on the standards used by these Linux desktops is <a href="http://www.freedesktop.org/">freedesktop.org</a>. For information on other Linux desktops please refer to the documentation for the desktops you are interested in.</p>
<p>Often, users do not use executable files directly, but instead launch applications by clicking icons on the desktop. These icons are representations of &quot;desktop entry files&quot; that contain a description of the application that includes information about its icon. Both desktop environments are able to retrieve the information in these files, and they use it to generate shortcuts to applications on the desktop, in the start menu, and on the panel.</p>
<p>More information about desktop entry files can be found in the <a href="http://www.freedesktop.org/Standards/desktop-entry-spec">Desktop Entry Specification</a>.</p>
<p>Although desktop entry files can usefully encapsulate the application's details, we still need to store the icons in the conventional location for each desktop environment. A number of locations for icons are given in the <a href="http://www.freedesktop.org/Standards/icon-theme-spec">Icon Theme Specification</a>.</p>
<p>Although the path used to locate icons depends on the desktop in use, and on its configuration, the directory structure beneath each of these should follow the same pattern: subdirectories are arranged by theme, icon size, and application type. Generally, application icons are added to the hicolor theme, so a square application icon 32 pixels in size would be stored in the <code>hicolor/32x32/apps</code> directory beneath the icon path.</p>
<a name="k-desktop-environment-kde"></a>
<h3 >K Desktop Environment (KDE)</h3>
<p>Application icons can be installed for use by all users, or on a per-user basis. A user currently logged into their KDE 4 desktop can discover these locations by using kde4-config, for example, by typing the following in a terminal window:</p>
<pre class="cpp">

  kde4<span class="operator">-</span>config <span class="operator">-</span><span class="operator">-</span>path icon

</pre>
<p>Applications using Qt 5 and KDE Frameworks 5 will find their icons in the list returned by this command:</p>
<pre class="cpp">

  qtpaths <span class="operator">-</span><span class="operator">-</span>locate<span class="operator">-</span>dirs GenericDataLocation icons

</pre>
<p>Typically, the list of colon-separated paths printed to stdout includes the user-specific icon path and the system-wide path. Beneath these directories, it should be possible to locate and install icons according to the conventions described in the <a href="http://www.freedesktop.org/Standards/icon-theme-spec">Icon Theme Specification</a>.</p>
<p>If you are developing exclusively for KDE, you may wish to take advantage of the <a href="http://techbase.kde.org/Development/CMake/Addons_for_KDE">KDE build system</a> to configure your application. This ensures that your icons are installed in the appropriate locations for KDE.</p>
<p>The KDE developer website is at <a href="http://techbase.kde.org/">http://techbase.kde.org/</a>.</p>
<a name="gnome"></a>
<h3 >GNOME</h3>
<p>Application icons are stored within a standard system-wide directory containing architecture-independent files. This location can be determined by using <code>gnome-config</code>, for example by typing the following in a terminal window:</p>
<pre class="cpp">

  gnome<span class="operator">-</span>config <span class="operator">-</span><span class="operator">-</span>datadir

</pre>
<p>The path printed on stdout refers to a location that should contain a directory called <code>pixmaps</code>; the directory structure within the <code>pixmaps</code> directory is described in the <a href="http://www.freedesktop.org/Standards/icon-theme-spec">Icon Theme Specification</a>.</p>
<p>If you are developing exclusively for GNOME, you may wish to use the standard set of <a href="http://developer.gnome.org/tools/build.html">GNU Build Tools</a>, also described in the relevant section of the <a href="http://developer.gnome.org/doc/GGAD/ggad.html">GTK+/Gnome Application Development book</a>. This ensures that your icons are installed in the appropriate locations for GNOME.</p>
<p>The GNOME developer website is at <a href="http://developer.gnome.org/">http://developer.gnome.org/</a>.</p>
</div>
<!-- @@@appicon.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2017 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>