admiral0
admiral0

Reputation: 183

Is it possible to have an animated QSystemTrayIcon?

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

Answers (3)

Šerg
Šerg

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

mosg
mosg

Reputation: 12381

I suppose that you have two ways:

  1. 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)

  2. The other way is to use QTimer and a few different images. Here I found an example.

Upvotes: 1

hluk
hluk

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

Related Questions