2

I am developing an application for RedHat 7.2, with Qt5.6.

My resource file 'qrc':

    <RCC>
        <qresource prefix="/">
            <file alias="APP_ICON">lw-3.png</file>
        </qresource>
    </RCC>

I want to set-up the application to use this resource as the application icon. Using the editor I have edited the main window and set the property 'windowIcon' to APP_ICON by choosing it from the resource file.

I've run qmake and built the application but the icon remains the default Qt icon.

I've tried adding this code to the main window constructor:

    QIcon objIcon = QIcon(":/APP_ICON");
    setWindowIcon(objIcon);

However this doesn't work either, what do I need to do?

[Edit] The application shown in the task bar does display the correct icon as set-up in the resource along side the application title, its just the icon in the file system that isn't correct.

SPlatten
  • 5,334
  • 11
  • 57
  • 128

2 Answers2

4

I'm sure it won't be what you hoped for, but here goes. The official Qt answer is here http://qt-project.org/doc/qt-5/appicon.html

Step 1: Install a 48x48 icon in the hicolor theme. This means copying a PNG file to /usr/share/icons/hicolor/48x48/apps. Optionally you can install icons in different sizes. For example, copying a svg icon in /usr/share/icons/hicolor/scalable/apps means most desktops will have one icon that works for all sizes.

It is recommended that the icons installed in the hicolor theme look neutral, since it is a fallback theme that will be used in combination with some very different looking themes. But if you don't have any neutral icon, then install whatever icon you have in the hicolor theme so that all applications get at least some icon in all themes.

Step 2: Create a text .desktop file in /usr/share/applications/ to tell gnome about your application. This will allow your application to be found via the gnome menu with appropriate icon BUT when browsing in nautilus/files the executable will still not show using your icon.

The /usr/share/applications/myapp.desktop file should contain something like:

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=MyAppName
Comment=My very special application description
Exec=/use/bin/myapp
Icon=/usr/share/icons/hicolor/scalable/apps/myapp.svg
Terminal=false
Categories=GNOME;Application;
StartupNotify=true
myk
  • 708
  • 2
  • 8
  • 20
  • Isn't there something that I can wrap up in the Qt IDE so that its automatic when the application is built ? I've tried the official Qt page before posting on StackOverflow, not success. – SPlatten Jun 29 '16 at 13:11
  • 1
    I'd also like that to be the case, but after a couple of days of searching this was the only approach I found (which also happened to work) - lets wait a bit, maybe someone else has a solution. – myk Jun 29 '16 at 13:27
1

The utility gio, can be used to associate metadata with a file including a custom icon file. Associating a custom icon with a file ensures that when the file is shown in Nautilus (Files) it is displayed using its associated icon.

To see the meta-data of file use:

gio info /path/to/file/file-name

To associate a custom icon with a file use:

gio set /path/to/file/file-name metadata::custom-icon "file:///path/to/file/icon-file-name"

Possibly as part of the linux / gnome installation you could execute a shell command to associate the icon.

myk
  • 708
  • 2
  • 8
  • 20