是否可以拥有动画QSystemTrayIcon?

时间:2010-10-08 06:21:15

标签: c++ qt

我似乎找不到任何关于此的信息。但很多kde应用都使用了动画图标。

据我所知设置为QIcon,gif不起作用,因为只会显示第一帧。

3 个答案:

答案 0 :(得分:3)

我没有尝试这个,但可能每隔几毫秒设置一个新图标。

/* 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)
*/

答案 1 :(得分:1)

我想你有两种方式:

  1. 尝试使用GIF动画文件(开始使用带QMovie的GIF播放),然后将其放入托盘(我不确定此情况)

  2. 另一种方法是使用QTimer和一些不同的图像。在这里,我找到了an example

答案 2 :(得分:0)

我确实喜欢这个:

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);