Setting the Qt Application Icon
来源:互联网 发布:网络传送带使用教程 编辑:程序博客网 时间:2024/06/01 10:10
Setting the Application Icon
The application icon, typically displayed in the top-left corner of an application's top-level windows, is set by calling theQWidget::setWindowIcon() 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
First, create an ICO format bitmap file that contains the icon image. This can be done with e.g. Microsoft Visual C++: SelectFile|New, then select the File tab in the dialog that appears, and chooseIcon. (Note that you do not need to load your application into Visual C++; here we are only using the icon editor.)
Store the ICO file in your application's source code directory, for example, with the namemyappico.ico. Then, create a text file called, say, myapp.rc in which you put a single line of text:
IDI_ICON1 ICON DISCARDABLE "myappico.ico"
Finally, assuming you are using qmake to generate your makefiles, add this line to yourmyapp.pro file:
RC_FILE = myapp.rc
Regenerate your makefile and your application. The .exe file will now be represented with your icon in 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 callingQWidget::setWindowIcon() 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 theIcon 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 makefiles, 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 ismyapp.pro, add this line to myapp.pro:
ICON = myapp.icns
This will ensure that qmake puts your icons in the proper place and creates anInfo.plist entry for the icon.
If you do not use qmake, you must do the following manually:
- Create an Info.plist file for your application (using the PropertyListEditor, found inDeveloper/Applications).
- Associate your .icns record with the CFBundleIconFile record in theInfo.plist file (again, using the PropertyListEditor).
- Copy the Info.plist file into your application bundle's Contents directory.
- Copy the .icns file into your application bundle's Contents/Resources directory.
Setting the Application Icon on Common Linux Desktops
In this section we briefly describe the issues involved in providing icons for applications for two common Linux desktop environments:KDE and GNOME. 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 isfreedesktop.org. For information on other Linux desktops please refer to the documentation for the desktops you are interested in.
Often, users do not use executable files directly, but instead launch applications by clicking icons on the desktop. These icons are representations of "desktop entry files" 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.
More information about desktop entry files can be found in the Desktop Entry Specification.
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 theIcon Theme Specification.
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 thehicolor/32x32/apps directory beneath the icon path.
K Desktop Environment (KDE)
Application icons can be installed for use by all users, or on a per-user basis. A user currently logged into their KDE desktop can discover these locations by usingkde-config, for example, by typing the following in a terminal window:
kde-config --path icon
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 theIcon Theme Specification.
If you are developing exclusively for KDE, you may wish to take advantage of theKDE build system to configure your application. This ensures that your icons are installed in the appropriate locations for KDE.
The KDE developer website is at http://developer.kde.org/.
GNOME
Application icons are stored within a standard system-wide directory containing architecture-independent files. This location can be determined by usinggnome-config, for example by typing the following in a terminal window:
gnome-config --datadir
The path printed on stdout refers to a location that should contain a directory calledpixmaps; the directory structure within the pixmaps directory is described in theIcon Theme Specification.
If you are developing exclusively for GNOME, you may wish to use the standard set ofGNU Build Tools, also described in the relevant section of theGTK+/Gnome Application Development book. This ensures that your icons are installed in the appropriate locations for GNOME.
The GNOME developer website is at http://developer.gnome.org/.
Setting the Application Icon on the Symbian platform
In order to set the application icon for Symbian platform applications, you need an SVG-T icon. For information on how to create SVG-T compliant icons, please refer tohttp://wiki.forum.nokia.com/index.php/How_to_create_application_icon(SVG)_in_S60_3rd_edition
Once the icon is available in the correct format and assuming you are using qmake to generate your makefiles, you only need to add a single line to your.pro project file. For example, if the name of your icon file is myapp.svg, and your project file ismyapp.pro, add this line to myapp.pro:
ICON = myapp.svg
- Setting the Qt Application Icon
- Setting the Application Icon
- How to set the QT Application icon in the windows.
- Qt Application Icon Setting(Qt在不同平台下的图标设置)
- 设置应用程序的图标(Setting the Application Icon)— Mac OS X
- How to embed an icon in a Qt application
- Download Qt, the cross-platform application framework
- QT 错误 Cannot start the terminal emulator 'xterm', change the setting in the Environment options.
- QT 错误 Cannot start the terminal emulator 'xterm', change the setting in the Environment options.
- Code Sign error: Application Identifier 'xxx' which doesn't match the current setting 'xxx'
- How are the icon files in my application bundle used on iPad and iPhone?
- How are the icon files in my application bundle used on iPad and iPhone
- 应用图标提示设置applicationIconBadgeNumber Attempting to badge the application icon but haven't
- iOS开发错误之Attempting to badge the application icon but haven't received permiss
- iOS开发-71】解决方案:Attempting to badge the application icon but haven't received permiss...
- Attempting to badge the application icon but haven't received permiss...
- Attempting to badge the application icon but haven't received permission解决方案
- 解决方案:Attempting to badge the application icon but haven't received permiss...
- cmd中运行java程序
- gzip,bzip2,tar,zip命令使用方法详解
- Python3.3 安装 MySQLdb(Ubuntu13.04)
- 为什么有些文件不能从svn服务器上更新下来
- 一个挺有用的获取tomcat项目路径的工具类
- Setting the Qt Application Icon
- Ubuntu 10.04 修改开机boot
- 从零开始学WCF(6)数据协定
- Flash&Flex大全
- [jbpm]一个完整的spring+jbpm+mysql整合例子
- Linux下安装Python-3.3.2
- C常见问题之字符串的数组形式与指针形式的区别
- SAE 搭建 Discuz
- java实现栈(链表方式)