J.Bob
J.Bob

Reputation: 13

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.

Upvotes: 1

Views: 5930

Answers (2)

maxik
maxik

Reputation: 1123

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.

Upvotes: 3

CJCombrink
CJCombrink

Reputation: 3950

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

Upvotes: 0

Related Questions