返回介绍

Setting the Application Icon

发布于 2019-10-04 14:57:36 字数 3405 浏览 1029 评论 0 收藏 0

The application icon, typically displayed in the upper left corner of the
application top-level windows, is set by calling the
QWidget::setIcon() method on top-level widgets.

In order to change the icon of the executable application file
itself, as it is presented on the desktop (i.e. prior to application
execution), it is necessary to employ another, platform-dependent
technique.

  • Setting the Application Icon on Windows
  • Setting the Application Icon on Mac OS X

Setting the Application Icon on Windows

First, create an ICO format bitmap file that contains the icon image. This
can be done with e.g. Microsoft Visual C++: Select "File|New...", then
select the "File" tab in the dialog that appears, and choose "Icon". (Note
that you do not need to load your application into Visual C++; here we are
only using its icon editor).

Store the ICO file in the source code directory of your application,
for example, with the name, "myappico.ico". Then, create a text file
called e.g. "myapp.rc" in which you put a single line of text:

IDI_ICON1               ICON    DISCARDABLE     "myappico.ico"

Lastly, assuming you are using qmake to generate your makefiles, add this
line to your "myapp.pro" file:

RC_FILE = myapp.rc

Regenerate your makefile and your application. The .exe file will now be
represented with your icon in e.g. Explorer.

If you do not use qmake, the necessary steps are: first, run the "rc"
program on the .rc file, then link your application with the resulting
.res file.

Setting the Application Icon on Mac OS X

The application icon, typically displayed in the application dock
area, is set by calling QWidget::setIcon() on a top-level widget. 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.

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.

Although many programs can create icon files (.icns), the recommended
approach is to use the Icon Composer program supplied by Apple (in the
Developer/Application folder). Icon Composer allows you to import several
different sized icons (for use in different contexts) as well as the masks
that go with them. Save the set of icons to a file in your project
directory.

If you are using qmake to generate
your make files, you only need to add a single line to your .pro
project file. For example, if the name of your icon file is
myapp.icns, and your project file is myapp.pro, add this line
to myapp.pro:

RC_FILE = myapp.icns

This will ensure that qmake puts your
icons in the proper place and creates a Info.plist entry for the
icon.

If you do not use qmake, you must do
the following manually:

  1. Create an Info.plist file for your application (using the
    PropertyListEditor, found in Developer/Applications).

  2. Associate your .icns record with the CFBundleIconFile record in the
    Info.plist file (again, using the PropertyListEditor).

  3. Copy both the icns and your Info.plist into your application bundle
    Resource directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文