Qt中设置窗口图标

转:https://blog.csdn.net/weiren2006/article/details/7438028

1、通过qtcreator新建一个文件filename.qrc,将图片添加到filename.qrc文件中:选择Add Prefix得到/new/prefix1,简单点改为/,再选Add Files,将文件添加进去,如images/photo.png

或者用文本编辑filename.qrc文件,改为

<RCC>
    <qresource prefix="/">
        <file>images/photo.png</file>
    </qresource>
</RCC>

2.将filename.qrc添加到工程中,在*.pro中添加:

RESOURCES += filename.qrc

3.在代码中添加

setWindowIcon(QIcon(":/images/photo.png"));

 

posted @ 2019-12-27 14:52  sgggr  阅读(2083)  评论(0编辑  收藏  举报