当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - How to include an icon in the title bar of window in Qt?

问题描述:

I want to be able to replace the existing standard icon with my own but I am unsure how to do so. I only started Qt one week ago so I don't know much about the application. In addition to this I looked at the Qt website but their method for adding an icon did not work on my computer.

网友答案:

Besides using a RC file (Windows) you may specify the icon directly using qmake.

win32: RC_ICONS = icon.ico

Make sure it detects the path correctly. In the provided case the icon resides in the project root directory right beside the project file.


For window icons you typically, if application wide applicable, use some method of QApplication.

...
QApplication app(argc, argv);
...
app.setWindowIcon(QIcon(":/icon");
...

which is consuming the resource file using the alias icon. Here is an example (res.qrc):

<RCC>
    <qresource prefix="/">
        <file alias="icon">icon.png</file>
    </qresource>
</RCC>

More information on resources are here.

网友答案:

Perhaps try the function setWindowIcon function on the QWidget or QApplication.

分享给朋友:
您可能感兴趣的文章:
随机阅读: