Reputation: 183
I can't seem to find any info about this. but a lot of kde apps use animated icons.
As i know it setting as QIcon a gif won't work, as only first frame will be displayed.
Upvotes: 4
Views: 1628
Reputation: 803
I did like this:
QMovie *movie = new QMovie(":/icons/icon.gif");
QLabel *label = new QLabel(this);
label->setMovie(movie);
movie->start();
QTimer *timer = new QTimer(this);
timer->setSingleShot(false);
connect(timer, &QTimer::timeout, [this,timer,label](){
trIcon->setIcon(label->movie()->currentPixmap());
timer->start(50);
});
timer->start(50);
Upvotes: 1
Reputation: 12381
I suppose that you have two ways:
Try to use GIF animated file (start playing with GIF with QMovie), and place it to the tray (i'm not sure about this case)
The other way is to use QTimer and a few different images. Here I found an example.
Upvotes: 1
Reputation: 6016
I didn't try this but it is probably possible by setting new icon every few milliseconds.
/* list of frames */
QLinkedList<QIcon> frames;
/* frames are icons created from images in application resources */
frames << QIcon(":/images/icon1.png") << QIcon(":/images/icon2.png");
/* set timer */
QTimer timer = new QTimer(this);
timer->setSingleShot(false);
connect(timer, SIGNAL(timeout()), this, SLOT(updateTrayIcon()));
timer->start(500); /* update icon every 500 milliseconds */
/*
updateTrayIcon function (SLOT) sets next tray icon
(i.e. iterates through QLinkedList frames)
*/
Upvotes: 3