2

我正在使用 Qt5.6 为 RedHat 7.2 开发应用程序。

我的资源文件'qrc':

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

我想设置应用程序以将此资源用作应用程序图标。使用编辑器我已经编辑了主窗口,并通过从资源文件中选择它来将属性“windowIcon”设置为 APP_ICON。

我已经运行了 qmake 并构建了应用程序,但该图标仍然是默认的 Qt 图标。

我尝试将此代码添加到主窗口构造函数中:

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

但是这也不起作用,我需要做什么?

[编辑] 任务栏中显示的应用程序在资源中显示正确的图标,在应用程序标题旁边设置,它只是文件系统中的图标不正确。

4

2 回答 2

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
于 2016-06-29T13:09:57.520 回答
1

实用程序 gio,可用于将元数据与包括自定义图标文件的文件相关联。将自定义图标与文件关联可确保当文件显示在 Nautilus(文件)中时,它会使用关联的图标显示。

要查看文件使用的元数据:

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

要将自定义图标与文件相关联,请使用:

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

可能作为 linux / gnome 安装的一部分,您可以执行 shell 命令来关联图标。

于 2018-03-13T16:23:37.683 回答