Results 1 to 12 of 12

Thread: How to set the application icon in Linux?

  1. #1
    Join Date
    Nov 2007
    Posts
    15
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default How to set the application icon in Linux?

    Hi,

    How to set the application icon in Linux?

    Thanks in advance

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set the application icon in Linux?


  3. #3
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to set the application icon in Linux?

    Quote Originally Posted by marcel View Post
    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

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to set the application icon in Linux?

    are you sure that the image path is right? Could you display the image you want to set as icon on a QLabel?

  5. #5
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to set the application icon in Linux?

    Quote Originally Posted by Lykurg View Post
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to set the application icon in Linux?

    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.

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to set the application icon in Linux?

    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.

  8. #8
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to set the application icon in Linux?

    Quote Originally Posted by Lykurg View Post
    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:

    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. QLabel hello;
    8. hello.resize(400, 300);
    9.  
    10. QPixmap pixmap(":/images/icon.png");
    11.  
    12. hello.setPixmap(pixmap);
    13. hello.show();
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. <RCC>
    2. <qresource prefix="/images/icon">
    3. <file>icon.png</file>
    4. </qresource>
    5. </RCC>
    To copy to clipboard, switch view to plain text mode 

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

  9. #9
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set the application icon in Linux?

    your prefix path is images/icon... so it should be images/icon/icon.png

    EDIT: oh.. tht was wrong. i forgot qrc
    Last edited by nish; 24th September 2010 at 09:39.

  10. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to set the application icon in Linux?

    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.

  11. #11
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to set the application icon in Linux?

    It also did not work when I change the pixmap path to: ":/icon.png". I really don't know what the problem was from

  12. #12
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to set the application icon in Linux?

    Ah, it works finally! Thank you very much, Lykurg and MrDeath

Similar Threads

  1. Mac application and the Dock Icon
    By sekelsenmat in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2007, 10:23
  2. Replies: 2
    Last Post: 9th June 2007, 19:19
  3. Replies: 2
    Last Post: 12th January 2007, 11:19
  4. Execution of a qt application on an arm linux device...
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 29th November 2006, 20:14
  5. Porting Qt application on windows from linux
    By safknw in forum Qt Programming
    Replies: 13
    Last Post: 22nd May 2006, 13:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.