设置Qt应用程序图标及应用程序名
2013-11-13 15:40
543 查看
原文/article/2675392.html
一直以来很纠结给qt应用程序添加图标问题,在网上收过一次,但是感觉不够完整,现将自己的实现过程记录下,以便以后查看:
通过网上的例子知道qt助手中有相关说明:
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.
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 choose Icon. (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 name myappico.ico. Then, create a text file called, say, myapp.rc in
which you put a single line of text:
Finally, assuming you are using qmake to generate your makefiles, add this line to your myapp.pro file:
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.
从上面可将方法分为两种:
1.使用软件的方法可设置程序窗口的默认图标,但是它无法改变应用程序文件.exe的图标。
2.使用qmake生成makefile的,如qt+eclipse,qt creator通过”If you do not use qmake"之前的方法就可以解决
3.使用qt+vs2010不是用qmake的情况,需要执行"If you do not use qmake..."方法,先将.rc文件添加到工程中,再编译.rc文件,最后重新连接下即可改变图标。
实现过程:
1.设置应用程序运行时所有窗口默认图标,
[cpp] view
plaincopy
QApplication a(argc, argv);
//获得可执行程序路径
[cpp] view
plaincopy
QString dir = QApplication::applicationDirPath();
//设置可执行程序路径为当前工作路径
QDir::setCurrent(dir);
QApplication::addLibraryPath("./plugins");
[cpp] view
plaincopy
QApplication::addLibraryPath("./images");
a.setWindowIcon(QIcon("./images/myappico.ico"));
2.通过qmake生成makefile实现过程:
a.找到一张图片.ico,名字改为myappico.ico;
b.创建一个新的文本文档,内部添加 IDI_ICON1 ICON DISCARDABLE "myappico.ico",并将文件重命名为myapp.rc;
c.在myapp.pro文件最后加上RC_FILE = myapp.rc,重新生成之后,就修改成功了
3.不用qmake生成makefile实现过程:
前面两步骤一样,最后一步改为,将.rc文件加载至工程中,通过右键工程——添加——已存在文件,添加后右键.rc文件编译,重新生成可执行文件后就修改成功了
一直以来很纠结给qt应用程序添加图标问题,在网上收过一次,但是感觉不够完整,现将自己的实现过程记录下,以便以后查看:
通过网上的例子知道qt助手中有相关说明:
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 tabin 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 the icon editor.)
Store the ICO file in your application's source code directory, for example, with the name myappico.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 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 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.
从上面可将方法分为两种:
1.使用软件的方法可设置程序窗口的默认图标,但是它无法改变应用程序文件.exe的图标。
2.使用qmake生成makefile的,如qt+eclipse,qt creator通过”If you do not use qmake"之前的方法就可以解决
3.使用qt+vs2010不是用qmake的情况,需要执行"If you do not use qmake..."方法,先将.rc文件添加到工程中,再编译.rc文件,最后重新连接下即可改变图标。
实现过程:
1.设置应用程序运行时所有窗口默认图标,
[cpp] view
plaincopy
QApplication a(argc, argv);
//获得可执行程序路径
[cpp] view
plaincopy
QString dir = QApplication::applicationDirPath();
//设置可执行程序路径为当前工作路径
QDir::setCurrent(dir);
QApplication::addLibraryPath("./plugins");
[cpp] view
plaincopy
QApplication::addLibraryPath("./images");
a.setWindowIcon(QIcon("./images/myappico.ico"));
2.通过qmake生成makefile实现过程:
a.找到一张图片.ico,名字改为myappico.ico;
b.创建一个新的文本文档,内部添加 IDI_ICON1 ICON DISCARDABLE "myappico.ico",并将文件重命名为myapp.rc;
c.在myapp.pro文件最后加上RC_FILE = myapp.rc,重新生成之后,就修改成功了
3.不用qmake生成makefile实现过程:
前面两步骤一样,最后一步改为,将.rc文件加载至工程中,通过右键工程——添加——已存在文件,添加后右键.rc文件编译,重新生成可执行文件后就修改成功了
相关文章推荐
- 设置Qt应用程序图标
- Qt应用程序的发布,exe文件图标设置
- 为QT应用程序设置图标
- Qt——设置Qt应用程序图标
- 3,Qt设置应用程序图标
- 设置Qt应用程序图标
- 为QT应用程序设置图标
- OpenCV3.2+Qt5.8.0+Win10开发视频监控系统----(1)Qt之设置应用程序图标
- Qt笔记——三步设置Qt应用程序图标
- Qt 设置应用程序图标(windows)
- vs 编译器下 为qt程序设置应用程序图标
- QT如何设置应用程序的图标
- Qt设置应用程序图标
- QT5.2 Assistant-设置应用程序图标
- 怎样设置Qt生成的应用程序图标
- Qt 5.7 on Android 设置应用程序图标和名称
- VS QT设置应用程序图标
- QT ——设置应用程序图标
- Mac OS上 Qt 应用程序图标的设置方式
- 设置Qt应用程序图标