Interactive application icon
-
@JonB It's actually really simple, the application's icon is just an image, so you just need an image representation of a widget, and when that widget changes, you can just update the application's icon like this:
pixmap = self.slider_frame.grab() self.setWindowIcon(QIcon(pixmap))
grab() returns a pixmap, update the pixmap each time the slider moves, set the pixmap as the new icon.
You can also do the same thing for the tray icon.
You can also use a QMovie animation, for examplepixmap = self.animation.currentPixmap()
So if you combine everything, you can have an event driven interactive application icon / system tray icon
-
@JonB It's actually really simple, the application's icon is just an image, so you just need an image representation of a widget, and when that widget changes, you can just update the application's icon like this:
pixmap = self.slider_frame.grab() self.setWindowIcon(QIcon(pixmap))
grab() returns a pixmap, update the pixmap each time the slider moves, set the pixmap as the new icon.
You can also do the same thing for the tray icon.
You can also use a QMovie animation, for examplepixmap = self.animation.currentPixmap()
So if you combine everything, you can have an event driven interactive application icon / system tray icon
-
@Mizmas And that would work in, say, GNOME? I thought that just uses a static file for its icon?
-
@Mizmas
...which is why I said it would probably depend on your platform/window manager which you didn't say...[TBH I had not noticed initially that this was Showcase, I thought you were asking if you could do this from Qt.] Your showcase is fine, just you might like to mention this if it's e.g. Windows-only as Qt is cross-platform.
-
@JonB using QWindow::setIcon this also works on Gnome/X11.
rough PoC:
QTimer timer; int i = 0; int iconSize = 32; int rectSize = 5; QPixmap pixmap(QSize{iconSize, iconSize}); timer.start(20); timer.callOnTimeout([&] { pixmap.fill(Qt::transparent); { QPainter painter(&pixmap); painter.drawRect(i, i , rectSize, rectSize); } i = (i + 1) % (iconSize - rectSize + 1); QIcon icon(pixmap); QGuiApplication::setWindowIcon(icon); QGuiApplication::allWindows().first()->setIcon(icon); });