Hi,

I'm trying to print a QGraphicsScene and I'm having some problems with the resulting size.

Qt Code:
  1. int iDPIs = 300;
  2. qreal qResolutionMmPx = 1 / ((double)iDPIs / 25.4); //mm / px
  3.  
  4. QPrinter qPrinter;
  5. QString qPDFFileName = "painter.pdf";
  6. qPrinter.setOutputFormat(QPrinter::PdfFormat);
  7. qPrinter.setOutputFileName(qPDFFileName);
  8. qPrinter.setPageSize(QPrinter::A4);
  9. qPrinter.setResolution(iDPIs);
  10.  
  11. QPainter qPainter(&qPrinter);
  12.  
  13. qPainter.drawRect(50/qResolutionMmPx,50/qResolutionMmPx,100/qResolutionMmPx,100/qResolutionMmPx);
To copy to clipboard, switch view to plain text mode 
This draws a 100x100mm rect perfectly.

This code tryies to print using a graphics scene:
Qt Code:
  1. int iDPIs = 300;
  2. qreal qResolutionMmPx = 1 / ((double)iDPIs / 25.4); //mm / px
  3.  
  4. pqScene = new QGraphicsScene(this);
  5. ui.graphicsView->setScene(pqScene);
  6. pqScene->addRect(0,0,100/qResolutionMmPx,100/qResolutionMmPx,QPen(Qt::blue)); //100x100mm desired rect
  7.  
  8. QPrinter qPrinter;
  9. QString qPDFFileName = "scene.pdf";
  10. qPrinter.setOutputFormat(QPrinter::PdfFormat);
  11. qPrinter.setOutputFileName(qPDFFileName);
  12. qPrinter.setPageSize(QPrinter::A4);
  13. qPrinter.setResolution(iDPIs);
  14.  
  15. QPainter qPainter(&qPrinter);
  16. pqScene->render(&qPainter);
To copy to clipboard, switch view to plain text mode 
This always gives me a rect about 203mm. Also changing the size of the rect item gives me always the same result size.

What I found is that changing the scene rect also changes the resulting size, so
Qt Code:
  1. pqScene->setSceneRect(0,0,1000,1000);
To copy to clipboard, switch view to plain text mode 
Gives me a rect that is 76,6mm

Can anyone explain me what I'm not understanding?

Thanks,