【转】设置Qt应用程序图标及应用程序名
一直以来很纠结给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 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:
- 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.设置应用程序运行时所有窗口默认图标,
- QApplication a(argc, argv);
- //获得可执行程序路径
- QString dir = QApplication::applicationDirPath();
- //设置可执行程序路径为当前工作路径
- QDir::setCurrent(dir);
- QApplication::addLibraryPath("./plugins");
- 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应用程序图标及应用程序名 【转载】
一直以来很纠结给qt应用程序添加图标问题,在网上收过一次,但是感觉不够完整,现将自己的实现过程记录下,以便以后查看: 通过网上的例子知道qt助手中有相关说明: Setting the Applicat ...
- 【Qt开发】设置Qt应用程序图标
[Qt开发]设置Qt应用程序图标 标签:[Qt开发] 首先,准备一个图标,例如:zx.ico,并新建一个文本文档,在里面添加一行: IDI_ICON1 ICON DISCARDABLE"zx ...
- 设置QT应用程序图标方法(Windows下)
学习笔记,言简意赅. 1- 新建文本文件,编辑输入 IDI_ICON1 ICON DISCARDABLE "./image/WindowIco.ico" 注意: ...
- QT添加程序图标及窗口图标
程序图标 材料准备 图标文件:*.ico文件,存放在源文件同一目录下,如"myapp.ico" 写入图标 向*.pro文件中,独立一行写入"RC_ICONS = *.ic ...
- Qt应用程序图标设置
Qt应用程序图标设置 本文仅仅适用于windows下,linux等不适用. 下面说的图标,指的是程序文件的图标,而不是托盘图标或者说运行时任务栏的图标(任务栏和程序窗口的图标在windows/linu ...
- Qt应用程序图标
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt应用程序图标 本文地址:http://techieliang.com/2017/1 ...
- Qt 添加程序图标和系统托盘图标
添加程序图标 第一种方法: 1.创建程序的时候,选择添加默认图标 2.替换程序目录下的ico文件,编译生成即可. 第二种方法: 比较适合一开始没有添加程序图标的情况 1.项目右键-->添加--& ...
- QT更改程序图标
方法只要几个步骤就好了,如下: 1.准备好一个ico格式的图标文件,例如demo.ico 2.创建一个rc文件, 例如demo.rc. 并copy下面代码: // Generated by ResEd ...
- 设置 Qt GUI程序 printf输出到独立控制台
随机推荐
- idea 运行scala代码 报错:Exception in thread "main" java.lang.NoClassDefFoundError: scala/Predef$ java.lang.NoClassDefFoundError: scala/Function0 Error: A JNI error has occurred, please check your installati
各种报错信息如下: java.lang.NoClassDefFoundError: scala/Function0 at java.lang.Class.getDeclaredMethods0(Nat ...
- Jfinal QuartzPlugin 简单使用案例
之前一直使用spring quartz感觉还挺好用的,就想着jfinal是不是也可以使用quartz插件,于是发现了QuartzPlugin和jfinal-scheduler<参考:https: ...
- 使用控制台程序搭建WebApi
原文参考: ASP.NET Web Api 2.2: Create a Self-Hosted OWIN-Based Web Api from Scratch 新建控制台程序,引入Owin包 PM&g ...
- mpvue图片轮播遇到的问题
小程序官方写法: <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" i ...
- 对CAP原理的理解
对CAP原理的理解 CAP原理按照定义,指的是C(Consistency)一致性,A(Availability)可用性,P(Partition tolerance)分区容错性在一个完整的计算机系统中三 ...
- 微信小程序——豆瓣电影——(1):基础入门
准备 Demo 项目地址 https://github.com/zce/weapp-demo Clone or Download(需准备GIT环境) $ cd path/to/project/root ...
- elasticSearch6源码分析(12)DiscoveryModule
1.DiscoveryModule概述 /** * A module for loading classes for node discovery. */ 2.discovery The discov ...
- [基础篇] 玄机网C#培训课程-初级.
课程目录 0x01第一课课前准备vs的选择与安装常用工具/网址 http://msdn.itellyou.cn/vs常用设置 0x02第二课C#的语法样式 编程风格VS的常用功能 俩个注意 ...
- Python的两种运行方式
从2015年5月19日注册博客园,立志于要通过写博客的方式,记录自己编程的点点滴滴,由于自己太懒,一直拖到现在,“拖延症”是病得改,今天终于写自己第一篇博客了,有点小激动! Python是由Guido ...
- [日常] Go语言圣经-竞争条件习题
package main import( "fmt" "sync" ) var balance int func Deposit(amount int) { b ...