lni
29th August 2013, 03:51
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
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 );
QSizeF pSize = printer->pageRect( QPrinter::Inch ).size();
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 );
QRectF targetRect( QPointF( 0, 0 ), QSizeF( pWidth, pHeight ) );
QRectF sourceRect( QPointF( 0, 0 ), QSizeF( sWidth, pHeight ) );
QPainter painter( printer );
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();
}
}
}
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
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 );
QSizeF pSize = printer->pageRect( QPrinter::Inch ).size();
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 );
QRectF targetRect( QPointF( 0, 0 ), QSizeF( pWidth, pHeight ) );
QRectF sourceRect( QPointF( 0, 0 ), QSizeF( sWidth, pHeight ) );
QPainter painter( printer );
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();
}
}
}