Hello,

I want to print on a paper(or pdf...) a picture, scaled to the maximum of the page, according to the picture aspectRatio. Then I want to display under this picture some RichText.
I have found three solutions, but each one has a serious drawback

The fisrt one correctly resize the picture, but doesn't enable me to put RichText(only normal text). I made an example below
Qt Code:
  1. #include <QtGui>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.  
  6. QApplication app(argc, argv);
  7. QPushButton bouton("Just a Button");
  8. bouton.show();
  9.  
  10.  
  11. QPrinter m_Printer(QPrinter::HighResolution);
  12. m_Printer.setOutputFormat(QPrinter::PdfFormat);
  13. m_Printer.setOutputFileName("baseprinted.pdf");
  14. QPainter painter (&m_Printer);
  15. QRect rect = painter.viewport();
  16. QRect OldWindow= painter.window();
  17. QPixmap m_Image("c:\\picture.jpg");
  18. QSize size = m_Image.size ();
  19. size.scale (rect.size (), Qt::KeepAspectRatio);
  20. painter.setViewport (0, 0, size.width (), size.height ());
  21. painter.setWindow (m_Image.rect ());
  22. painter.drawPixmap (m_Image.rect(), m_Image);
  23. painter.setViewport(rect);
  24. painter.setWindow(OldWindow);
  25. QRect tmp;
  26. QFont ComicMS("Comic Sans MS", 40);
  27. painter.setFont(ComicMS);
  28. tmp.setX(0);
  29. tmp.setY(size.height());
  30. tmp.setWidth(rect.width());
  31. tmp.setHeight(rect.height()-size.height());
  32. painter.drawText(tmp, Qt::AlignHCenter | Qt::AlignTop, "Texte <b>!</b>");
  33. return app.exec();
  34. }
To copy to clipboard, switch view to plain text mode 

The second one, enables me to put html, but the picture hasn't the good dimensions(it could be larger)
Qt Code:
  1. m_Printer.setOutputFormat(QPrinter::PdfFormat);
  2. m_Printer.setOutputFileName("printed.pdf");
  3. m_Printer.setPageMargins(0,0,0,0,QPrinter::Point);
  4. Docu.addResource(QTextDocument::ImageResource, QUrl( "monImage.jpg" ), m_Image.scaled( m_Printer.paperRect(QPrinter::Point).size().toSize() ,Qt::KeepAspectRatio, Qt::SmoothTransformation) );
  5. Docu.setHtml("<img src=\"monImage.jpg\"/><br/><b>Hello</b> World");
  6. Docu.print(&m_Printer);
To copy to clipboard, switch view to plain text mode 

Then the last solution. It works well, but the text is to small(it's logic). And I dont know how to add other text at the rigtht size.
Qt Code:
  1. m_Printer.setOutputFormat(QPrinter::PdfFormat);
  2. m_Printer.setOutputFileName("mixteprinted.pdf");
  3. QPainter painter (&m_Printer);
  4. QRect rect = painter.viewport();
  5. QRect OldWindow= painter.window();
  6. QSize size = m_Image.size ();
  7. size.scale (rect.size (), Qt::KeepAspectRatio);
  8. painter.setViewport (0, 0, size.width (), size.height ());
  9. painter.setWindow (m_Image.rect ());
  10. Docu.addResource(QTextDocument::ImageResource, QUrl( "monImage.jpg" ), m_Image );
  11. Docu.setHtml("<img src=\"monImage.jpg\"/><br/><b>Hello</b> World");
  12. Docu.drawContents(&painter);
  13. Docu.setHtml("<b>Hello</b> GUYS");
  14. painter.setViewport(rect);
  15. painter.setWindow(OldWindow);
  16. QFont ComicMS("Comic Sans MS", 40);
  17. Docu.setDefaultFont(ComicMS);
  18. Docu.drawContents(&painter);
To copy to clipboard, switch view to plain text mode 


Each solution has a drawback that I cant avoid. I'm focused on the last solution, where my goal is then just to add some text at the right size after the Docu.drawContents(&painter);
But after many tryes, I can't find tsomething similar to painter.drawText() that put the text at the right size.

If you have any Ideas?

Thank you and Merry Christmas