PDA

View Full Version : Set QApplication icon without using the rc/qrc file ?



Nyphel
22nd March 2007, 15:59
Hello,

I need to set an icon for my application :)
But...

I don't really know how to use the rc file, and I don't want to use it. If I understood weel, it is plateform dependant.

So there is the qrc file, that seems not to be plateform dependant.
The matter is that :
- I don't know how to use it too
- It seems to load the ressources in memory at the launch of the application. I can't allow that for my application, that need to use as less memory as possible :crying:

Is there another solution ?
What I would like is to say, for example :

QApplication app(argc, argv);
app.setIcon("my_icon.xpm");

wysota
22nd March 2007, 17:29
If you set an icon, you have to load it into memory anyway and I'm sure you can spare few hundred bytes for a small png image. But if you don't want it that way, them simply create a QPixmap from file:

QApplication app(...);
app.setIcon(QPixmap("my_icon.xpm"));

just remember that you're using a relative path here.

Nyphel
23rd March 2007, 09:17
Thanks Wysota :)
But it says : "QApplication has no member named 'setIcon' :(


.

jpn
23rd March 2007, 09:29
But it says : "QApplication has no member named 'setIcon' :(

QApplication::setWindowIcon() (http://doc.trolltech.com/4.2/qapplication.html#windowIcon-prop)
QWidget::setWindowIcon() (http://doc.trolltech.com/4.2/qwidget.html#windowIcon-prop)
Setting the Application Icon (http://doc.trolltech.com/4.2/appicon.html)

Nyphel
23rd March 2007, 12:43
So, it isn't possible to set the icon for all environments at the same time ?

jpn
23rd March 2007, 13:02
So, it isn't possible to set the icon for all environments at the same time ?
You didn't follow and read the links, did you? The icon, which typically displayed in the top-left corner of a window, is set by calling QApplication::setWindowIcon() or QWidget::setWindowIcon():

QApplication::setWindowIcon() <== set default window icon for all windows in the application
QWidget::setWindowIcon() <== set window icon for a specific window

This approach is platform independent.

However, if you want to set an icon for the executable, which is seen in file managers and such, you must use platform dependent solutions. This is all explained in Setting the Application Icon (http://doc.trolltech.com/4.2/appicon.html).

Nyphel
23rd March 2007, 14:13
Thanks jpn.

What I need is setting the icon for the executable.
This is the reason why I told about the rc and qrc files :)

And yes, I have read the links ;)

jpn
23rd March 2007, 14:25
What I need is setting the icon for the executable.
This is the reason why I told about the rc and qrc files :)
Ok, in this case there is no other way around than using platform dependent solutions described in.. you already know where. :) Qt's resource files (.qrc) won't help you with this. You will have to use a Windows resource file (.rc) on Windows and/or other mechanisms appropriate to the platform in question.

Nyphel
23rd March 2007, 16:06
Thanks jpn :(.
I wasn't sure of it, cause Qt is made in order not to be plateform dependant, so I expected there was an other solution :).