November 7, 2011

thomas@itest thomas@itest
Lab Rat
2 posts

How to change taskbar icon during runtime on windows

 

Hi all,

I’ve created a Qt application to talk with a remote device and I want to change the taskbar icon to show if the device is connected or not.

I’ve tried it thanks to QWidget::setWindowIcon() on my mainwindow and later with QApplication::setWindowIcon().

Both works fine when I run my app from Qtcreator.

But, after deploying it, when I run my application “normally” (say windows start menu), the icon shown in the taskbar is the .exe file’s icon (set thanks to Setting the Application Icon [doc.qt.nokia.com]) and not the mainwindow icon…

This result is the same on XP, Vista and Seven …

What am i missing ?

Thanks in advance,
tom.

5 replies

November 7, 2011

fluca1978 fluca1978
Ant Farmer
524 posts

This could help to set the exe icon:http://doc.qt.nokia.com/4.7-snapshot/appicon.html

November 7, 2011

broadpeak broadpeak
Hobby Entomologist
360 posts

I think, you won’t see the QMainWindow’s icon on the taskbar, because that icon is a Windows Resource Icon.
In widget, you use Qt resource icon.
Completely different.

November 7, 2011

thomas@itest thomas@itest
Lab Rat
2 posts

thank you for your prompt answers !

@fluca1978 : I don’t have any problem with the exe icon. It’s correctly set thanks to the way explained in your link. My problem is that it’s this icon which is shown in the task bar instead of those I wan’t to set during runtime.

@broadpeak : I’m affraid I don’t understand what you mean (I’m a newbie …) :
I can set all widget icons I want inside my application but not the taskbar one because it is inevitably managed by the OS ?
I won’t be able to change it programmatically ?

November 7, 2011

broadpeak broadpeak
Hobby Entomologist
360 posts

As I know, there are two kind of icons:
Windows Resource Icon for applications (all other, yet Visual C++ uses too)
and
Qt Resource Icon for inside(!) in a Qt applications,
for example widgets, dialogs and so one.
The two are different!
For example:
the application icon is platform dependent!
The other is platform INdependent.

November 8, 2011

fluca1978 fluca1978
Ant Farmer
524 posts

If I get it right the taskbar is showing the exe icon while you want another icon. As Broadpeak explained, the icon in the taskbar is platform dependent and depends on how the application “taskbar” on windows manages icons. I don’t think there is a common and simple solution for this.

 
  ‹‹ [Solved] Validating when a button is pressed      Set pixels of RowWrapPolicy::WrapLongRows ››

You must log in to post a reply. Not a member yet? Register here!