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. Set icon for top left title bar of all windows and taskbar

Set icon for top left title bar of all windows and taskbar

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 5 Posters 300 Views 1 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.
  • B Bonnie

    @why_bother said in Set icon for top left title bar of all windows and taskbar:

    I've looked at https://doc.qt.io/qt-6/appicon.html that mentions setIcon() and I'm totally confused, as I don't understand what the difference between setIcon() and setWindowIcon() is, let alone which one I'm supposed to use.

    setIcon() is for QWindow, which we usually don't use directly.
    setWindowIcon() is for QApplication, it will call QWindow::setIcon() internally for every window.

    As for the linked documentation, it is actually for changing the icon of the executable file, so it need to be configured in the project file, instead of in the code, and need to be certain icon format, instead of any picture format.
    When the executable file icon is set successfully, it should become the default window icon for QApplication, so there would be no need to call QApplication::setWindowIcon() or QWindow::setIcon() if you only have one icon to show. (This is my experience on Windows, not sure if Linux is the same case.)

    W Offline
    W Offline
    why_bother
    wrote last edited by
    #7

    @Bonnie

    Thank you Bonnie.

    So to be clear; I use setWindowIcon() to set the icon for the icon at the top left side of the window title bar? Please just answer yes or no. And if no, then how exactly do I do it?

    1 Reply Last reply
    0
    • W Offline
      W Offline
      why_bother
      wrote last edited by
      #8

      test_icon.png

      (sorry for the delay in posting screenshot, but it kept saying I had to wait 600 seconds to post)

      I 1 Reply Last reply
      0
      • JonBJ JonB

        @why_bother
        The first thing in your situation is to temporarily get rid of trying to use a resource. Put the icon in an external file at fixed location, verify it's good and pass the full, absolute path when creating the icon. Now you don't have to worry about resources, paths or build procedures. You can also use both setIcon() & setWindowIcon() so you don't have to wonder which one is appropriate while you test. That is how I approach a situation like this. I assume that does not resolve for you?

        Which then perhaps leaves you as @Christian-Ehrlicher says: perhaps your Manjaro or its window manager just does not do what you want? Do you have a choice of window managers/interfaces --- like xcb or wayland or whatever desktop--- which you could check?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote last edited by
        #9

        @JonB said in Set icon for top left title bar of all windows and taskbar:

        The first thing in your situation is to temporarily get rid of trying to use a resource.

        Please see his last post. Even my testcase with an internal icon does not work. It's the wm...

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        JonBJ 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @JonB said in Set icon for top left title bar of all windows and taskbar:

          The first thing in your situation is to temporarily get rid of trying to use a resource.

          Please see his last post. Even my testcase with an internal icon does not work. It's the wm...

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote last edited by JonB
          #10

          @Christian-Ehrlicher
          Yes you may well be right. My post was really intended for OP to have tested earlier, so that next time they might break a similar problem down before getting lost in considerations which could be eliminated.

          1 Reply Last reply
          0
          • JonBJ JonB

            @why_bother
            The first thing in your situation is to temporarily get rid of trying to use a resource. Put the icon in an external file at fixed location, verify it's good and pass the full, absolute path when creating the icon. Now you don't have to worry about resources, paths or build procedures. You can also use both setIcon() & setWindowIcon() so you don't have to wonder which one is appropriate while you test. That is how I approach a situation like this. I assume that does not resolve for you?

            Which then perhaps leaves you as @Christian-Ehrlicher says: perhaps your Manjaro or its window manager just does not do what you want? Do you have a choice of window managers/interfaces --- like xcb or wayland or whatever desktop--- which you could check?

            W Offline
            W Offline
            why_bother
            wrote last edited by
            #11

            @JonB

            While Christian is correct; I already did try it without using the resource file and it made no difference whatsoever.

            So no, it doesn't resolve anything.

            JonBJ 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @why_bother said in Set icon for top left title bar of all windows and taskbar:

              So I don't understand why it will not show. What's the problem?

              Since this icon is only a hint to the window manager - the problem is the window manager not honoring this hint.

              W Offline
              W Offline
              why_bother
              wrote last edited by
              #12

              @Christian-Ehrlicher

              I don't understand what you mean by "hint". What does that mean? I don't understand your comment at all.

              In any case, I know it is embedding my icon in the executable (using the resource file), so that isn't the problem. But that said, since I'm using KDE and as far as I know KDE uses Qt itself, and all other graphical apps I have installed do have their icons show up in the top left hand corner of the their window title bar; I don't understand why it's not working in my app (or even in a simple test case as above)? I can get it to display the same icon in a QMessageBox using QPixmap(). So again, I don't understand.

              Without trying to be rude, can you just tell me what in the hell I have to do to get the bloody thing to actually display in the top left corner of the window's title bar (for all windows)?

              Again, I'm new to programming with Qt, so I really have no idea how to get this bloody thing to just display the icon in the top left corner of the window's title bar. Can I just have a simple example of what I need to do? I literally have no idea what to do next.

              Christian EhrlicherC 1 Reply Last reply
              0
              • W why_bother

                @Christian-Ehrlicher

                I don't understand what you mean by "hint". What does that mean? I don't understand your comment at all.

                In any case, I know it is embedding my icon in the executable (using the resource file), so that isn't the problem. But that said, since I'm using KDE and as far as I know KDE uses Qt itself, and all other graphical apps I have installed do have their icons show up in the top left hand corner of the their window title bar; I don't understand why it's not working in my app (or even in a simple test case as above)? I can get it to display the same icon in a QMessageBox using QPixmap(). So again, I don't understand.

                Without trying to be rude, can you just tell me what in the hell I have to do to get the bloody thing to actually display in the top left corner of the window's title bar (for all windows)?

                Again, I'm new to programming with Qt, so I really have no idea how to get this bloody thing to just display the icon in the top left corner of the window's title bar. Can I just have a simple example of what I need to do? I literally have no idea what to do next.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote last edited by
                #13

                @why_bother said in Set icon for top left title bar of all windows and taskbar:

                I don't understand what you mean by "hint". What does that mean? I don't understand your comment at all.

                The window decoration is part of the window manager, Qt just can say it wants an icon or e.g. the close button upper left. But if the window manager ignores this Qt can not do anything against.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1
                • W why_bother

                  @JonB

                  While Christian is correct; I already did try it without using the resource file and it made no difference whatsoever.

                  So no, it doesn't resolve anything.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote last edited by
                  #14

                  @why_bother said in Set icon for top left title bar of all windows and taskbar:

                  So no, it doesn't resolve anything.

                  I know that. It was intended as a helpful suggestion for the future, as I know you said you are new.

                  1 Reply Last reply
                  0
                  • W why_bother

                    test_icon.png

                    (sorry for the delay in posting screenshot, but it kept saying I had to wait 600 seconds to post)

                    I Offline
                    I Offline
                    IgKh
                    wrote last edited by
                    #15

                    @why_bother Ah you are on Wayland. Wayland does not allow windows to set their own icons, because security or something.

                    There is an experimental upcoming extension protocol for setting window icons from within the application which is not widely implemented. Until then, any API you can call will do exactly nothing.

                    The correct way to set a window icon under Wayland, is to install a desktop file with the 'Icon' key set to a name of an installed icon, and make sure the compositor knows how to associate your app with the desktop file. It is usually automatic for installed applications, but you might need to fiddle with QGuiApplication::setDesktopFileName.

                    The orange W icon is the stock fallback most compositors use when they can't figure out the right desktop entry.

                    I W 2 Replies Last reply
                    0
                    • I IgKh

                      @why_bother Ah you are on Wayland. Wayland does not allow windows to set their own icons, because security or something.

                      There is an experimental upcoming extension protocol for setting window icons from within the application which is not widely implemented. Until then, any API you can call will do exactly nothing.

                      The correct way to set a window icon under Wayland, is to install a desktop file with the 'Icon' key set to a name of an installed icon, and make sure the compositor knows how to associate your app with the desktop file. It is usually automatic for installed applications, but you might need to fiddle with QGuiApplication::setDesktopFileName.

                      The orange W icon is the stock fallback most compositors use when they can't figure out the right desktop entry.

                      I Offline
                      I Offline
                      IgKh
                      wrote last edited by
                      #16

                      @IgKh said in Set icon for top left title bar of all windows and taskbar:

                      There is an experimental upcoming extension protocol for setting window icons from within the application which is not widely implemented

                      Just for completeness, the protocol is xdg-toplevel-icon-v1. In is implemented in KDE's Wayland compositor starting 6.3 and in Qt starting version 6.9. Under a compatible version combination, setWindowIcon works also under Wayland. Since OP is using Qt 5, that is not the case.

                      It should be further noted that some desktop environments (notably Gnome), force applications to use client-side decorations. When Qt is drawing its' own window decoration, the icon set via setWindowIcon will appear on the window frame, but won't appear elsewhere - overview screen, dock, Alt+Tab switcher, etc.

                      Therefore specifying a static icon via a desktop file is still the way to go unfortunately.

                      1 Reply Last reply
                      2
                      • I IgKh

                        @why_bother Ah you are on Wayland. Wayland does not allow windows to set their own icons, because security or something.

                        There is an experimental upcoming extension protocol for setting window icons from within the application which is not widely implemented. Until then, any API you can call will do exactly nothing.

                        The correct way to set a window icon under Wayland, is to install a desktop file with the 'Icon' key set to a name of an installed icon, and make sure the compositor knows how to associate your app with the desktop file. It is usually automatic for installed applications, but you might need to fiddle with QGuiApplication::setDesktopFileName.

                        The orange W icon is the stock fallback most compositors use when they can't figure out the right desktop entry.

                        W Offline
                        W Offline
                        why_bother
                        wrote last edited by
                        #17

                        @IgKh

                        Thank you IgKh. I am indeed on Wayland and have just been playing around with a desktop file for the test case above and you are correct. So I managed to finally get my icon to display by doing what you've described above.

                        What I did:

                        1. created a .desktop file and copied it to /usr/share/applications/
                        2. copied icon files to the relevant directories in /usr/share/icons/hicolor/

                        and that made Wayland display it in both the top left corner of the window and taskbar.

                        So as you said, it's Wayland that was the issue, not the window manager.

                        Although, while I did have a call to QGuiApplication::setDesktopFileName() in the main() function and it did work; I commented it out just to see what would happen and it still displayed my custom icon in both the top left corner of the window and taskbar. So I assume it's not necessary to have that call there?

                        Thanks for your posts IgKh!

                        1 Reply Last reply
                        0
                        • W why_bother has marked this topic as solved

                        • Login

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