Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Icon for linux application
Forum Updated to NodeBB v4.3 + New Features

Icon for linux application

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 908 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    atom_352
    wrote 22 days ago last edited by
    #1

    Hello, how could i add icon for my app? I need the icon to be displayed in the system tray when launched, I am writing the application for Ubuntu and other Linux systems, my build system is cmake, and the language is C++ (I don’t know if this is important)

    J 1 Reply Last reply 22 days ago
    0
    • A atom_352
      22 days ago

      @Pl45m4 Thanks!! But should it look like this?

      mainwindow.cpp

      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          icon();
      }
      
      void MainWindow::icon()
      {
           QMainWindow::setWindowIcon(QIcon("qrc:/new/icons/img/information.png"));
      }
      

      Because at startup the taskbar still displays the standard icon

      P Offline
      P Offline
      Pl45m4
      wrote 22 days ago last edited by
      #8

      @atom_352

      This also works

      {
          ui->setupUi(this);
          QMainWindow::setWindowIcon(QIcon("qrc:/new/icons/img/information.png"));
      }
      

      Because at startup the taskbar still displays the standard icon

      If you want to have your icon as "shortcut" / desktop icon on Linux you need to follow @JonB 's solution in the topic linked by @jsulm above.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      A 1 Reply Last reply 22 days ago
      1
      • A atom_352
        22 days ago

        Hello, how could i add icon for my app? I need the icon to be displayed in the system tray when launched, I am writing the application for Ubuntu and other Linux systems, my build system is cmake, and the language is C++ (I don’t know if this is important)

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote 22 days ago last edited by
        #2

        @atom_352 See https://forum.qt.io/topic/102167/how-to-add-qt-application-icon-in-ubuntu

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply 22 days ago
        2
        • J jsulm
          22 days ago

          @atom_352 See https://forum.qt.io/topic/102167/how-to-add-qt-application-icon-in-ubuntu

          A Offline
          A Offline
          atom_352
          wrote 22 days ago last edited by
          #3

          @jsulm , i tried somthing from that, but probably did something wrong, I think I didn’t really understand where to write this and how to point to an image if it is in .qrc resources

          J 1 Reply Last reply 22 days ago
          0
          • A atom_352
            22 days ago

            @jsulm , i tried somthing from that, but probably did something wrong, I think I didn’t really understand where to write this and how to point to an image if it is in .qrc resources

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote 22 days ago last edited by
            #4

            @atom_352 Did you try QMainWindow::setWindowIcon(), I think this is what you need and you can use an icon embedded in a rosource file.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            A 1 Reply Last reply 22 days ago
            2
            • J jsulm
              22 days ago

              @atom_352 Did you try QMainWindow::setWindowIcon(), I think this is what you need and you can use an icon embedded in a rosource file.

              A Offline
              A Offline
              atom_352
              wrote 22 days ago last edited by
              #5

              @jsulm , Yes, I tried to use exactly this, but where can I write this, and is it necessary to use the qicon class?

              P 1 Reply Last reply 22 days ago
              0
              • A atom_352
                22 days ago

                @jsulm , Yes, I tried to use exactly this, but where can I write this, and is it necessary to use the qicon class?

                P Offline
                P Offline
                Pl45m4
                wrote 22 days ago last edited by
                #6

                @atom_352 said in Icon for linux application:

                but where can I write this

                Anywhere ;-)
                But I don't think your neighbors will like you if you paint that on their door.

                However, to set your MainWindow icon you need to write it in a function that is called when creating your QMainWindow :)

                is it necessary to use the qicon class

                You can construct a QIcon from file, either QRC or directly from file string.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                A 1 Reply Last reply 22 days ago
                1
                • P Pl45m4
                  22 days ago

                  @atom_352 said in Icon for linux application:

                  but where can I write this

                  Anywhere ;-)
                  But I don't think your neighbors will like you if you paint that on their door.

                  However, to set your MainWindow icon you need to write it in a function that is called when creating your QMainWindow :)

                  is it necessary to use the qicon class

                  You can construct a QIcon from file, either QRC or directly from file string.

                  A Offline
                  A Offline
                  atom_352
                  wrote 22 days ago last edited by atom_352
                  #7

                  @Pl45m4 Thanks!! But should it look like this?

                  mainwindow.cpp

                  MainWindow::MainWindow(QWidget *parent)
                      : QMainWindow(parent)
                      , ui(new Ui::MainWindow)
                  {
                      ui->setupUi(this);
                      icon();
                  }
                  
                  void MainWindow::icon()
                  {
                       QMainWindow::setWindowIcon(QIcon("qrc:/new/icons/img/information.png"));
                  }
                  

                  Because at startup the taskbar still displays the standard icon

                  P 1 Reply Last reply 22 days ago
                  0
                  • A atom_352
                    22 days ago

                    @Pl45m4 Thanks!! But should it look like this?

                    mainwindow.cpp

                    MainWindow::MainWindow(QWidget *parent)
                        : QMainWindow(parent)
                        , ui(new Ui::MainWindow)
                    {
                        ui->setupUi(this);
                        icon();
                    }
                    
                    void MainWindow::icon()
                    {
                         QMainWindow::setWindowIcon(QIcon("qrc:/new/icons/img/information.png"));
                    }
                    

                    Because at startup the taskbar still displays the standard icon

                    P Offline
                    P Offline
                    Pl45m4
                    wrote 22 days ago last edited by
                    #8

                    @atom_352

                    This also works

                    {
                        ui->setupUi(this);
                        QMainWindow::setWindowIcon(QIcon("qrc:/new/icons/img/information.png"));
                    }
                    

                    Because at startup the taskbar still displays the standard icon

                    If you want to have your icon as "shortcut" / desktop icon on Linux you need to follow @JonB 's solution in the topic linked by @jsulm above.


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    A 1 Reply Last reply 22 days ago
                    1
                    • P Pl45m4
                      22 days ago

                      @atom_352

                      This also works

                      {
                          ui->setupUi(this);
                          QMainWindow::setWindowIcon(QIcon("qrc:/new/icons/img/information.png"));
                      }
                      

                      Because at startup the taskbar still displays the standard icon

                      If you want to have your icon as "shortcut" / desktop icon on Linux you need to follow @JonB 's solution in the topic linked by @jsulm above.

                      A Offline
                      A Offline
                      atom_352
                      wrote 22 days ago last edited by
                      #9

                      @Pl45m4 Ok! Finally, i understand, thank you so much

                      1 Reply Last reply
                      0
                      • A atom_352 has marked this topic as solved 22 days ago
                      • S Offline
                        S Offline
                        SimonSchroeder
                        wrote 22 days ago last edited by
                        #10

                        I am using AppImages (created with linuxdeploy and linuxdeployqt) to have portable applications. These rely on a .desktop file which is supposed to be portable between KDE and Gnome (and hopefully other desktop environments). The .desktop file plays together with the xdg-utils. You can install these with xdg-desktop-menu or xdg-desktop-icon. I'd expect that through this they would also immediately show the icon in the taskbar when launched this way. (You can even register file extensions with xdg-mime and than open file with the associated program with xdg-open–much like macOS's open command.)

                        If I am not mistaken, this is the official link for .desktop files: https://specifications.freedesktop.org/desktop-entry-spec/latest/index.html

                        1 Reply Last reply
                        1
                        • E Offline
                          E Offline
                          eman086
                          wrote 21 days ago last edited by
                          #11

                          To add a system tray icon in a C++ app on Ubuntu/Linux using CMake, you can use libappindicator or Qt (if using Qt framework). Here's a short summary:

                          Use libappindicator for GTK-based apps:

                          Install: sudo apt install libappindicator3-dev

                          Link in CMake: target_link_libraries(your_app appindicator3-0.1)

                          Set icon: app_indicator_set_icon_full(indicator, "icon-name", "description");

                          Or use Qt:

                          Use QSystemTrayIcon and set icon with setIcon(QIcon(":/icon.png"));

                          Make sure the icon file is included in your build and accessible at runtime.

                          1 Reply Last reply
                          0

                          2/11

                          21 May 2025, 13:09

                          9 unread
                          • Login

                          • Login or register to search.
                          2 out of 11
                          • First post
                            2/11
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved