2 Attachment(s)
Problem on multi-pages preview with QGraphicsScene
Hi,
I have a QGraphicsScene with size( 318, 3565 ), and need to print it on 4 pages of A4 paper.
But first I need to preview it. I got ghost in between pages in the previewer (see attached images). Is there a way to remove the ghost?
Many thanks
Code:
void QfwPrintPreviewWindow
::printPreview( QPrinter* printer
) {
qreal left, top, right, bottom;
printer
->getPageMargins
( &left,
&top,
&right,
&bottom,
QPrinter::Inch );
printer
->setPageMargins
( left,
0, right,
0,
QPrinter::Inch );
qreal pWidth = pSize.width() * printer->logicalDpiX();
qreal pHeight = pSize.height() * printer->logicalDpiY();
QSizeF sSize
= m_scene
->sceneRect
().
size();
qreal sWidth = sSize.width();
qreal sHeight = sSize.height();
int pages = std::ceil( sHeight / pHeight );
for ( int idx = 0; idx < pages; idx++ ) {
painter.drawRect( targetRect );
m_scene->render( &painter, targetRect, sourceRect );
// move printer 1 page down
sourceRect.translate( 0, pHeight );
// create new page
if ( idx < pages - 1 ) {
printer->newPage();
}
}
}
Re: Problem on multi-pages preview with QGraphicsScene