[Qt C++] – Transparent, dynamically generated from text tray icon
#include <QApplication> #include <QSystemTrayIcon> #include <QPixmap> #include <QPainter> #include <QFont> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPixmap pixmap(20, 20); // small size should work fine on every platform pixmap.fill(Qt::transparent); // set transparency of the icon QPainter painter(&pixmap); int size = 15; // size 15 looks nice on KDE and GNOME QFont font("", size); painter.setFont(font); QString theText = "3"; // this will be the text in the system tray icon painter.drawText(QPoint(5, size+1), theText); QSystemTrayIcon *tray = new QSystemTrayIcon(); tray->setIcon(QIcon(pixmap)); tray->show(); return app.exec(); } |