有没有方法用pyqt将动画GIF作为系统托盘图标?

2 投票
1 回答
3124 浏览
提问于 2025-04-16 10:43

我用pyqt创建了一个静态的PNG图像作为托盘图标。

我用GIF图像做的也是静态托盘图标。请问用pyqt能让它在系统托盘中动起来吗?

QtGui.QSystemTrayIcon.__init__(self, parent)
self.setIcon(QtGui.QIcon("Image.gif"))

1 个回答

3

使用 QMovie 来播放动画的GIF,并在每次新帧事件时更新托盘图标:

m_icon = new QSystemTrayIcon();
m_icon->show();
m_gif = new QMovie(":/animated.gif");
connect(m_gif, SIGNAL(frameChanged(int)), this, SLOT(updateIcon()));
m_gif->start();

...

void MyWidget::updateIcon()
{
    m_icon->setIcon(m_gif->currentPixmap());
}

抱歉,这里是C++的例子,我没有安装PyQt。

撰写回答