关键类:QSystemTrayIcon
if (visible) {
QPixmap pixmap;
if (!pixmap.load(":/res/logo.png")) {
qDebug() << "Failed to load icon from resource file.";
return;
}
pixmap = pixmap.scaled(16, 16);
QPainter painter(&pixmap);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen); // 不绘制边框
painter.setBrush(Qt::red);
painter.drawEllipse(0, 8, 8, 8);
QIcon icon(pixmap);
setIcon(icon);
}
else {
setIcon(QIcon(":/res/logo.png"));
}
先将logo加载到QPixmap,再在QPixmap上用QPainter绘制红点。最后调用QSystemTrayIcon::setIcon