Important: Please read the Qt Code of Conduct -

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");
        QFont font = painter.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);"light_icon.png");

    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?

  • Lifetime Qt Champion

    @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.

  • Lifetime Qt Champion

    @tham Then I would change the icon itself.

  • @jsulm I will give them this suggestion, thanks

Log in to reply