//Adding items
int iScreenDPIs = logicalDpiX(); //96 DPI
qreal qScreenResolutionMmPx = 1 / ((double)iScreenDPIs / 25.4);
pqScene->setSceneRect(0,0,210/qScreenResolutionMmPx,297/qScreenResolutionMmPx);
pqScene
->addRect
(50/qScreenResolutionMmPx,
50/qScreenResolutionMmPx,
100/qScreenResolutionMmPx,
100/qScreenResolutionMmPx,
QPen(Qt
::blue));
//Add text item to see if it mantain the font "point size"
QGraphicsItemText *pqTextItem = pqScene->addText("TEST"·,qFont);
pqTextItem->setPos(50/qResolutionMmPx,50/qResolutionMmPx);
//Rendering
int iPrinterDPIs = 300; //Desired printing resolution
qreal qPrinterResolutionMmPx = 1 / ((double)iPrinterDPIs / 25.4);
pqScene
->render
(&qPainter,
QRectF(0,
0,
210/qPrinterResolutionMmPx ,
297/qPrinterResolutionMmPx
));
//Render the scene scaled to the desired size
//Adding items
int iScreenDPIs = logicalDpiX(); //96 DPI
qreal qScreenResolutionMmPx = 1 / ((double)iScreenDPIs / 25.4);
pqScene->setSceneRect(0,0,210/qScreenResolutionMmPx,297/qScreenResolutionMmPx);
pqScene->addRect(50/qScreenResolutionMmPx,50/qScreenResolutionMmPx,100/qScreenResolutionMmPx,100/qScreenResolutionMmPx,QPen(Qt::blue));
//Add text item to see if it mantain the font "point size"
QFont qFont("Arial",10);
QGraphicsItemText *pqTextItem = pqScene->addText("TEST"·,qFont);
pqTextItem->setPos(50/qResolutionMmPx,50/qResolutionMmPx);
//Rendering
int iPrinterDPIs = 300; //Desired printing resolution
qreal qPrinterResolutionMmPx = 1 / ((double)iPrinterDPIs / 25.4);
pqScene->render(&qPainter,QRectF(0,0,210/qPrinterResolutionMmPx ,297/qPrinterResolutionMmPx )); //Render the scene scaled to the desired size
To copy to clipboard, switch view to plain text mode
As it seems to adapt the scene to the deisred rect.
Bookmarks