How to set an application icon in Qt
10,175
QT's documentation for QWindow::setWindowIcon
should be what you need.
- Make an icon file (you appear to have done this already: room.ico
- Add your icon file to a QT resource file (.qrc or .rc) which you should add to your project (the documentation discusses how to do this
- Use
setWindowIcon
and pass in aQIcon
:-
app.setWindowIcon(QIcon(":/room.ico"));
(this assumes your file is in the resource file)
-
Your problem appears to be that you didn't prepend :/
when passing in the filename to QIcon
.
![The Beast](https://i.stack.imgur.com/aMzi0.jpg?s=256&g=1)
Comments
-
The Beast almost 2 years
I have some trouble trying to set an icon for my QT application.
The icon is named "room.ico" and is on the same directory as the source file.
Here is the code :
#include <QApplication> #include <QWidget> int main( int argc, char *argv[ ] ) { QApplication app( argc, argv) ; QWidget fenetre; fenetre.setWindowIcon(QIcon("room.ico")); // Nothing happens fenetre.setWindowTitle("Heloo"); fenetre.show(); return app.exec() ; }
I have tried to add
win32:RC_ICONS += room.ico
in the.pro file
but that didn't work. I have also tried"./room.ico"
but still no icon.I have tried to use this :
QPixmap pixmap = QPixmap ("room.ico"); fenetre.setWindowIcon(QIcon(pixmap));
And guess what !!! it didn't work ... i'm just a newbie to QT :p
Any suggestions will be appreciated , thanks
-
Alexander V over 8 yearsMake sure you suggest the proper string in function argument.
-
Tas over 8 years@AlexanderVX Ah well spotted, thanks. I've updated the answer.
-
The Beast over 8 years@Tas What i did by following the documentation is adding
RC_ICONS = myappico.ico
to the .pro file and i have to run qmake command to make the icon appear . Now it's working just withapp.setWindowIcon(QIcon("room.ico"));
+ No ressource file needed :) -
Vladimir Bershov over 8 yearsResolved question about doean't working mothod RC_ICONS += stackoverflow.com/a/18814639/4149835
-
user3405291 over 5 yearsIt is important to use image path with
QIcon
like this:app.setWindowIcon(QIcon(":/image.png"));
and NOT image URL like this:app.setWindowIcon(QIcon("qrc:/image.png"));
notice that image path doesn't have theqrc
in it