0

Whenever I run the script of my app or the compiled exe, the icon doesn't show in the taskbar on Windows. When I run my script in Pycharm on Linux, the icon shows just fine.

Here's how I'm adding the icon in my script:

app.setWindowIcon(QIcon("images/images/icon.ico"))

And here's how I'm adding the icon to the spec file compiled with PyInstaller:

icon=['icon.ico']

I tried using a QPixmap and I got the same result. I also tried having the icon in the same folder as my main.py file, but to no avail.

Update:

I was first using PySide2, now I migrated to PySide6. I'm now compiling and developing on Windows 10. I followed all the solutions in this SO question. When I don't add the AppUserModelID, the taskbar icon doesn't even appear when running the app from my IDE. When I do, it does show. However, after compilation, it does not.

I tried using a PNG, I tried a 32x32 icon, 48x48, nothing. I ran my .exe on another machine, still not appearing.

UPDATE:

Only thing that worked for me after days of trial and error is the answer from Saren Tasciyan on this question and Nuno André's rendition.

  • Did you actually add that `icon.ico` at the specified relative path to your package? – musicamante Feb 10 '23 at 23:56
  • you need to build execute file for Windows OS for showing icon and etc... – Ferhat Mousavi Feb 10 '23 at 23:57
  • Try to add the code from [this SO answer](https://stackoverflow.com/a/1552105/14956120). I also use pyside2 on windows and had the same problem. This answer was the one that actually worked for me. The icon doesn't necessarily need to be a `*.ico` file. – Carl HR Feb 11 '23 at 00:12
  • @musicamante I have added the .ico file at the specified path. – ConfusedCode Feb 11 '23 at 00:35
  • @CarlHR To be fully honest, I don't understand what the variable myappid should be. – ConfusedCode Feb 11 '23 at 00:39
  • @ConfusedCode Ensure that it has been properly and actually packaged and that its path reflects the cwd of the binary: if `QIcon("images/images/icon.ico").isNull()` returns `True`, than you did something wrong. Also, note that if you bundled the binary as a single file, Qt won't be able to access it, since those resources become "virtual" (as they are only available from memory, not as physical files). – musicamante Feb 11 '23 at 00:47
  • It can be any kind of string, but just make sure it's unique. The [ms docs](https://learn.microsoft.com/pt-br/windows/win32/shell/appids?redirectedfrom=MSDN#how-to-form-an-application-defined-appusermodelid) recommends you to use this pattern: `CompanyName.ProductName.SubProduct.VersionInformation`. So if you set something like: `mycompany.myproduct.mysubproduct.v0`, it should work. – Carl HR Feb 11 '23 at 00:49
  • @CarlHR Apologies for the late response. I tried the suggested solution with Ronan's addition as well and it did not work for me. – ConfusedCode Feb 19 '23 at 14:22

0 Answers0