问题描述:

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.

相关阅读:
Top