Images moved while printing the QGraphicsScene
I am experiencing the problem with printing the contents of a QGraphicsScene. I create a printer and a painter using this printer. Then I simply render the QGraphicsScene using this painter. Everything looks fine when I store rendered graphics scene to an image (apart of the fact that the background is green), but when I want to render to a printer, the images from my graphics scene are moved and overlap each over. Text fields seem to be ok. This happens on windows, using microsoft xps document writer, as well as any hardware printer, so I think this is not connected to a specific driver.
I am printing a care labels for clothes, so paper sizes are small. Typically 40x100mm.
Any suggestions?? Could this be a QT bug??
Here is the code that I use:
QPrinter printer(QPrinterInfo::printerInfo(name)); printer.setPageMargins(0,0,0,0,QPrinter::Millimeter); printer.setResolution(QPrinter::HighResolution); printer.setOutputFormat(QPrinter::NativeFormat); printer.setFullPage(true); printer.setPaperSize(QSizeF((label->getWidth()-2)/pixelToMmMultiplier,(label->getHeight()-2)/pixelToMmMultiplier), QPrinter::Millimeter); QPointF mainRectPos = label->getMainRectPos(); QPainter painter(&printer); QRectF sourceRect = QRectF(QPointF(mainRectPos.x()+1, mainRectPos.y()+1),QSizeF(label->getWidth()-2, label->getHeight()-2)); label->getGraphicsScene()->render(&painter, QRectF(), sourceRect, Qt::IgnoreAspectRatio);
Yes it could be a bug. :) Often its something else though :)
That is a bit odd as rendering to screen or printer is very alike in Qt.
Did you try with setOutputFormat and pdf`?
Does pic also overlap when pdf?