1)首先在程序的源码文件夹下边建立一个存放资源文件(比如图片)的文件夹.
建立资源文件夹的位置不要选错了。
2)然后在右键当前项目,然后选"择添加新文件"
3)然后选择"Qt资源文件"
4)然后输入资源文件的名字(以.qrc后缀结尾)
建立好资源文件之后,就为资源文件添加“前缀”
5)然后把这个前缀修改为/
6)接下来就说往其中添加图片了(静态的我一般添加为png)
7)添加好资源图片的样子
8)使用资源图片,主要是路径
newAction->setIcon(QIcon(":/images/new.png"))
qt的版本,是4还是5。你可以查看assistant中的Setting the Application Icon
里面有详细的设置应用程序图标的说明。
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 the icon editor.)
Store the ICO file in your application's source code directory, for example, with the name myappico.ico.
Then, assuming you are using qmake to generate your makefiles, you only need to add a single line to your .pro project file:
RC_ICONS = myappico.ico
Finally, regenerate your makefile and your application. The .exe file will now be represented by your icon in Explorer.
However, if you already have an .rc file, for example, with the name myapp.rc, which you want to reuse, the following two steps will be required. First, put a single line of text to the myapp.rc file:
IDI_ICON1 ICONDISCARDABLE "myappico.ico"
Then, add this line to your myapp.pro file:
RC_FILE = myapp.rc
If you do not use qmake, the necessary steps are: first, create an .rc file and run the rc or windres program on the .rc file, then link your application with the resulting .res file.
首先,你需要创建一个包含图标的ICO格式的位图文件。VC下:选择 文件|新建,选择对话框中的文件标签,再选择ICON。
将ICO文件保存在程序源代码的目录下,比如命名为myappico.ico.
假设你使用qmake来生成makefiles文件,你只需要在.pro文件中添加一行:
RC_ICONS = myappico.ico
最后,重新生成makefile和应用程序。然后,exe文件就会显示你设置的图标了。
不过,如果你已经有了一个.rc文件的话,比如myapp.rc,添加下面的两行。首先,在myapp.rc中添加一行:
IDI_ICON1 ICONDISCARDABLE "myappico.ico"
然后在.pro中添加一行:
RC_FILE = myapp.rc
如果你用的不是qmake,必要的步骤有:首先,创建一个.rc文件,然后运行rc或者windres程序,最后将你的应用程序和.res文件链接在一块就行了。
Icon”就可以看到在各种平台设置Qt程序图标的方法。Setting the Application Icon on WindowsFirst, create an ICO format bitmap file that contains the iconimage. This can be done with e.g. Microsoft Visual C++: SelectFile|New, then select the File tab in the dialog that appears, andchoose Icon. (Note that you do not need to load your applicationinto 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 filecalled, say, myapp.rc in which you put a single line of text:IDI_ICON1ICONDISCARDABLE"myappico.ico"Finally, assuming you are using qmake to generateyour makefiles, add this line to your myapp.pro file:RC_FILE = myapp.rcRegenerate your makefile and your application.The .exe file will now be represented with your icon inExplorer.If you do not use qmake, the necessary steps are: first, run therc program on the .rc file, then link your application with theresulting .res file. *** 作如下:首先准备个ICO图标。例如:myappico.ico用记事本新建个文件,里面就写一行:IDI_ICON1 ICON DISCARDABLE “myappico.ico”保存改名为 myapp.rc并把它和你的图标myappico.ico一起复制到你的QT工程项目的目录。用记事本打开你的QT工程文件(如 “myapp.pro” ),在里面最后新添一行保存,编译你的工程,成功了吧。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)