Hello,
I'm trying to make system tray icon which contains text but it fails miserably.
Firstly the icon is made of 2 parts, one which contains text using a truetype icon fonts and another part with normal fonts.
One issues is that the application crashes, I cannot pinpoint the method which causes the crash but I think it's the draw method. I cannot find which is the issue because if I put breakpoints into the debugger the application works if don't it returns to normal behavior partly working.
Secondly:
If I put one part of the text into the pixmap with a size of 22 x 22 the text appears correctly, if I put it inside a 44 x 22 (w x h) pixmap the drawing is correctly placed but it becomes blurry, you should be able to find picture into attachments.
This is the code which shows the non-blurred number 4:
tempPixmap.
fill(QColor(0,
0,
0,
0));
tempPainter.
setPen(QColor(Qt
::white));
tempPainter.drawText(tempPixmap.rect(), Qt::AlignCenter, "4");
iconPainter.
drawPixmap(QRect(0,
0,
22,
22), tempPixmap
);
trayIcon
->setIcon
(QIcon(pixmap
));
QPixmap tempPixmap(22, 22);
tempPixmap.fill(QColor(0,0,0,0));
QPainter tempPainter(&tempPixmap);
tempPainter.setPen(QColor(Qt::white));
tempPainter.drawText(tempPixmap.rect(), Qt::AlignCenter, "4");
QPixmap pixmap(22,22);
pixmap.fill(QColor(0,0,0,0));
QPainter iconPainter(&pixmap);
iconPainter.drawPixmap(QRect(0, 0, 22, 22), tempPixmap);
trayIcon->setIcon(QIcon(pixmap));
To copy to clipboard, switch view to plain text mode
This is the code which shows the blurred version:
tempPixmap.
fill(QColor(0,
0,
0,
0));
tempPainter.
setPen(QColor(Qt
::white));
tempPainter.drawText(tempPixmap.rect(), Qt::AlignCenter, "4");
iconPainter.
drawPixmap(QRect(22,
0,
22,
22), tempPixmap
);
trayIcon
->setIcon
(QIcon(pixmap
));
QPixmap tempPixmap(22, 22);
tempPixmap.fill(QColor(0,0,0,0));
QPainter tempPainter(&tempPixmap);
tempPainter.setPen(QColor(Qt::white));
tempPainter.drawText(tempPixmap.rect(), Qt::AlignCenter, "4");
QPixmap pixmap(44,22);
pixmap.fill(QColor(0,0,0,0));
QPainter iconPainter(&pixmap);
iconPainter.drawPixmap(QRect(22, 0, 22, 22), tempPixmap);
trayIcon->setIcon(QIcon(pixmap));
To copy to clipboard, switch view to plain text mode
Can someone help me solve this issue?
Bookmarks