Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Draw text on image using Qt



  • I want to draw text on an image. I use this code, but I do not see any text on the image.

    ImageSaver::ImageSaver(QObject *parent) :
        QObject(parent)
    {
    }
    
    void ImageSaver::save(const QString &path) const
    {
    	img_.save(path);
        QImage image(path);
        QPainter p(&image);
        p.setPen(QPen(Qt::red));
        p.setFont(QFont("Times", 12, QFont::Bold));
        p.drawText(image.rect(), Qt::AlignCenter, "Text");
    }
    


  • @neda
    I used your code and works for me. I tested the image once the text is written using save.

    text

    text


Log in to reply