Solved Add "Demo" text under windowIcon of QMainWindow
-
How could I add text under the window icon of QMainWIndow?I try to draw the text into the icon, but it is too small to see them.
QImage icon(":/pics/some_icon.png"); QPainter painter(&icon); QPen pen("red"); pen.setWidth(3); painter.setPen(pen); painter.setRenderHint(QPainter::TextAntialiasing); QFont font = painter.font(); font.setPointSize(28); font.setStyleStrategy(QFont::PreferAntialias); painter.setFont(font); QFontMetrics metric(font); QString const str("Demo"); QRect const text_rect = metric.boundingRect(str); qDebug()<<(icon.height() - text_rect.height()); painter.drawText(QPoint(icon.width() / 2 - text_rect.width() / 2, icon.height() - text_rect.height() - 1), str); icon.save("light_icon.png"); setWindowIcon(QIcon(QPixmap::fromImage(icon)));
Do I have a way to add text under window icon?Thanks
ps : Is it possible to add text under icon of tray bar too?
-
@tham Wouldn't it be better to add "Demo" to the window caption?
-
@jsulm Totally agree with you, but customer ask me to add text under the icon.
-
@tham Then I would change the icon itself.
-
@jsulm I will give them this suggestion, thanks