PDA

View Full Version : How to set the application icon in Linux?



live_07
24th December 2007, 22:00
Hi,

How to set the application icon in Linux?

Thanks in advance

marcel
24th December 2007, 22:10
Have you tried QApplication::setWindowIcon()?

poplar
23rd September 2010, 18:39
Have you tried QApplication::setWindowIcon()?

Hi, I'm using QApplication::setWindowIcon() to set the icon for the application with the qt resource, but it didn't work. Could you please tell me how to set the icon in the window title application? Is there any limitation for the format of the icon? I'm using ubuntu, gnome. Can I use *.png or I must use *.ico? I really appreciate any help

Lykurg
23rd September 2010, 18:41
are you sure that the image path is right? Could you display the image you want to set as icon on a QLabel?

poplar
23rd September 2010, 18:53
are you sure that the image path is right? Could you display the image you want to set as icon on a QLabel?

I haven't tried. I'm developing in eclipse, then I have a src folder to store the header and source files. Insides the src folder, I also have an images folder which stores images and .qrc file, so the path is ":/images/icon.png". Did I make some thing wrong? Please tell me, I'm totally new to Qt :(. Thanks a lot

Lykurg
23rd September 2010, 19:39
its hard to tell if you are doing it right without seeing any piece of code. So as said, simply add a QLabel to your mainwindow and set a pixmap on it. When you create the pixmap use the exact same path as you do for the window icon. Check if you can see the icon on the label. Then we move further.

ChrisW67
23rd September 2010, 22:37
If the qrc file and the image are in the same directory then possibly the ":/images/icon.png" should be ":/icon.png" but it is hard to say for sure.

poplar
24th September 2010, 09:27
its hard to tell if you are doing it right without seeing any piece of code. So as said, simply add a QLabel to your mainwindow and set a pixmap on it. When you create the pixmap use the exact same path as you do for the window icon. Check if you can see the icon on the label. Then we move further.

I tried with the QLabel, but it didn't work too :(. Maybe there was something wrong in my qrc file. I'm developing using eclipse running on ubuntu. I created 2 new folders: src and images. In src folder, I put the main function in main.cpp which is:



#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel hello;
hello.resize(400, 300);

QPixmap pixmap(":/images/icon.png");

hello.setPixmap(pixmap);
hello.show();
return app.exec();
}

In the images folder, I put the icon.png and hello.qrc files. The qrc file is generated by eclipse, which is:


<RCC>
<qresource prefix="/images/icon">
<file>icon.png</file>
</qresource>
</RCC>

When running, the form displayed nothing. Could you please see what wrong here? Thank you very much for your help.

nish
24th September 2010, 09:29
your prefix path is images/icon... so it should be images/icon/icon.png

EDIT: oh.. tht was wrong. i forgot qrc :(

Lykurg
24th September 2010, 09:31
and as a hint: you can give an alias to the file itself. Then you can change the file as you like without changing you code.

poplar
24th September 2010, 09:32
It also did not work when I change the pixmap path to: ":/icon.png". I really don't know what the problem was from :(

poplar
24th September 2010, 09:39
Ah, it works finally! Thank you very much, Lykurg and MrDeath :)