QApplication: modify Windows systray using QWinTaskbarButton
-
Hi,
I have a QT application (QT .9.1) and I need to modify the icon in the windows taskbar, when I have an error. I am trying with QWinTaskbarButton, it seems to be really simple but I failed.
My application is a QtQuickControlsApplication (a QApplication), where I have a manager QObject class.
In this class I create a QQmlApplicationEngine, which I use to load the main QML.
From the documentation (http://doc.qt.io/qt-5/qwintaskbarbutton.html#details):
QWinTaskbarButton *button = new QWinTaskbarButton(widget); button->setWindow(widget->windowHandle()); button->setOverlayIcon(QIcon(":/loading.png"));
But i don't know what to set in 'widget' and 'widget->windowHandle()'
I have tried to get a widget from the qApp but failed:
qApp->activeWindow() is NULL qApp->topLevelWindows().at(0) is valid, but failed: QWinTaskbarButton *button = new QWinTaskbarButton(qApp->topLevelWindows().at(0)); button->setWindow(qApp->allWidgets().at(0)->windowHandle()); button->setOverlayIcon(QIcon(":/images/icon.png"));
I would appreciate any help,
Thanks in advance,
Diego -
@Diego-Donate
why don't you simply use the corresponding QML type of WinTaskbarButton? -
Thanks!! This works!!
My problem is that I need to show a number over the custom icon, is it possible?
Regards,
Diego -
- implement a custom QQuickImageProver
- set the wintaksbar icon to
"image://myimageprovider/icon?number=2"
, or also possible simplyimage://mytaskbarimageprovider/2
(whatever it easier for your needs) - in the image provider you have to parse the received url for the number and paint it into a QPixmap and return the pixmap
-
Thanks! I will try that