QTQML添加程序图标的方法

QTQML添加程序图标的方法,第1张

QT/QML添加程序图标的方法

使用QT/QML实现的程序需要加入app图标的方法:

1. 制作ICON格式图标,其他格式的图片可以通过ICON转换工具转换;

2. 项目文件加入(.pro) RC_ICONS = app.ico, app.ico就是app图标的名字;

3. qmake->重新构建->运行。

VS2013+Qt

一.设置程序图标

1.在创建项目时注意选择

它会自动生成一个*.ico文件,若不想用,直接替换掉即可。

2.若忘记选择这一步,则可以自己手动创建一个*.rc文件,内容参考例子,添加到项目里,效果一样。

例如:IDI_ICON1   ICON   DISCARDABLE     “child.ico"

3.也可在程序里使用setWindowIcon()来添加

例如:

QIcon icon("D:\\Qt\\project(creator)\\serial\\1.jpg")

w.setWindowIcon(icon)

二.设置系统托盘图标

.h文件:

例如:QStstemIcon m_sysTray

.cpp文件:

m_sysTray.setToolTip("")//设置提示文字

m_sysTray.setIcon(QIcon("路径"))//设置图标

QMenu* menu = new QMenu()//托盘菜单

menu->addAction(ui.actionExit)//可添加托盘右键菜单

m_sysTray.setContextMenu(menu)//设置右键菜单

m_sysTray.show()//显示

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文件链接在一块就行了。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11665330.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存