Hello,
I'm trying to generate a modified image starting from a preexisting PNG file and drawing some text on it. I'm not getting what I think I should get
In particular, I have some issues with font sizes.
I have found that the PNG resolution plays a role in the calculation of the actual pixel size of the font, if I increase the resolution and keep the font size fixed, the actual rendered text is smaller. The sizes do not match what I see if I do the same in inkscape, but this is not a problem. My problem is that there seems to be a "minimum pixel size" which limits the size of the smallest font I can draw. Right now I have the PNG at 72x72 dpi and a font size of 2 looks identical to font size 10.

The code:
Qt Code:
  1. int main(int argc, char **argv)
  2. {
  3. QApplication a(argc, argv);
  4. QImage* card = new QImage("blank72.png");
  5. QPainter* painter = new QPainter(card);
  6. QFont* FontText = new QFont("Serif", 2, QFont::Normal);
  7. QFont* FontText2 = new QFont("Serif", 10, QFont::Normal);
  8. painter->setRenderHint(QPainter::TextAntialiasing, true);
  9. painter->setPen(Qt::black);
  10. painter->setFont(*FontText);
  11. painter->drawText(QRect(0,0,256,128), Qt::TextWordWrap, "Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt");
  12. painter->setFont(*FontText2);
  13. painter->drawText(QRect(0,128,256,128), Qt::TextWordWrap, "Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt");
  14. QLabel* label = new QLabel(0);
  15. label->setPixmap(QPixmap::fromImage(*card));
  16. label->show();
  17.  
  18. return a.exec();
  19. }
To copy to clipboard, switch view to plain text mode 

blank72.png is a 256x256 white image with 72dpi resolution.

Side question: is there any easy way to have the text justified?