I can Screenshot from a QML component using grabToImage and use QPrinter to print that image,

I want to display that image fit to A4 paper page or print to center of A4 paper.
But the image is draw left of paper.

Qt Code:
  1. void pr::print(QVariant data)
  2.  
  3. {
  4. QImage img = qvariant_cast<QImage>(data);
  5. QPrinter printer;
  6. QPrintDialog *dlg = new QPrintDialog(&printer,0);
  7. if(dlg->exec() == QDialog::Accepted) {
  8.  
  9. QPainter painter(&printer);
  10. printer.setPageSize(QPrinter::A4);
  11.  
  12. //painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
  13. painter.drawImage(QPoint(0,0),img);
  14. printer.setFullPage(true);
  15. painter.end();
  16. }
  17.  
  18. }
To copy to clipboard, switch view to plain text mode