Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Draw text on image using Qt

Draw text on image using Qt

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    neda
    wrote on last edited by
    #1

    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");
    }
    
    RatzzR 1 Reply Last reply
    0
    • N neda

      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");
      }
      
      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by Ratzz
      #2

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

      text

      text

      --Alles ist gut.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved