I am developing a simple painting tool using Qt. For that I modified Qt's scribble code to draw text on an image. I can draw text on a normal jpgg image using the below code. But when I load big image(high resolution image), the text overlaps each other. I tried several technique but not get a perfect result

Code


Qt Code:
  1. QPainter painter(&image);
  2.  
  3. painter.setPen(m_myPenColor);//(QPen(m_myPenColor, myPenWidth,
  4. painter.setBrush(QBrush(m_myPenColor));
  5.  
  6. painter.setFont(m_myFont );
  7.  
  8. QFontMetricsF fm(m_myFont);
  9. qreal pixelsHigh = fm.height();
  10. qreal pixelwidthMil = fm.width("First Text");
  11. qreal pixelwidthMm = fm.width("Second Text");
  12. qreal pixelWidthMax= (pixelwidthMil>=pixelwidthMm)?pixelwidthMil:pixelwidthMm;
  13. int iX=0,iY=0;
  14. iX = endPoint.x();
  15.  
  16. iY = endPoint.y()+(int)pixelsHigh;
  17.  
  18. painter.drawText(iX+2, iY, "First Text");
  19. iY = iY + (int)pixelsHigh+1;
  20. painter.drawText(iX+2, iY, "Second Text");
  21.  
  22. pixelsHigh = (pixelsHigh*2)+6;
  23.  
  24. pixelWidthMax = pixelWidthMax+6;
  25. update(endPoint.x()-2, endPoint.y()-2, (int)pixelWidthMax,(int)pixelsHigh);
To copy to clipboard, switch view to plain text mode