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

(sorry for the delay in posting screenshot, but it kept saying I had to wait 600 seconds to post)
-
@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 bothsetIcon()&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?
@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...
-
@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...
@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. -
@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 bothsetIcon()&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?
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.
-
@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.
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.
-
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.
@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.
-
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.
@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.
-

(sorry for the delay in posting screenshot, but it kept saying I had to wait 600 seconds to post)
@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.
-
@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.
@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,
setWindowIconworks 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
setWindowIconwill 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.
-
@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.
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:
- created a .desktop file and copied it to /usr/share/applications/
- 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!
-
W why_bother has marked this topic as solved