Create a resources file named resources.qrc
:
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file>path/to/icon.png</file>
</qresource>
</RCC>
Make sure that path/to/icon.png
is an actual path, relative to the directory that contains resources.qrc
.
In your .pro
file, include the resource:
TARGET = your_app
TEMPLATE = app
QT += widgets
RESOURCES += path/to/resources.qrc
Again, make sure that path/to/resources.qrc
exists, relative to the directory that contains the project file.
After compiling, your resource will be embedded into your executable. It can be accessed like:
setWindowIcon(QIcon(":/path/to/icon.png"));
If the icon is not appearing, try this stackoverflow question or this one.
Another approach would be to use the Application Icon. This will set the application icon for your application on the desktop and start menus, and also on the top left corner of QMainWindow
s and QDialogs
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…