Results 1 to 2 of 2

Thread: Problem on multi-pages preview with QGraphicsScene

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

    Qt Code:
    1. void QfwPrintPreviewWindow::printPreview( QPrinter* printer )
    2. {
    3. qreal left, top, right, bottom;
    4. printer->getPageMargins( &left, &top, &right, &bottom, QPrinter::Inch );
    5. printer->setPageMargins( left, 0, right, 0, QPrinter::Inch );
    6.  
    7. QSizeF pSize = printer->pageRect( QPrinter::Inch ).size();
    8. qreal pWidth = pSize.width() * printer->logicalDpiX();
    9. qreal pHeight = pSize.height() * printer->logicalDpiY();
    10.  
    11. QSizeF sSize = m_scene->sceneRect().size();
    12. qreal sWidth = sSize.width();
    13. qreal sHeight = sSize.height();
    14.  
    15. int pages = std::ceil( sHeight / pHeight );
    16.  
    17. QRectF targetRect( QPointF( 0, 0 ), QSizeF( pWidth, pHeight ) );
    18. QRectF sourceRect( QPointF( 0, 0 ), QSizeF( sWidth, pHeight ) );
    19.  
    20. QPainter painter( printer );
    21.  
    22. for ( int idx = 0; idx < pages; idx++ ) {
    23. painter.drawRect( targetRect );
    24. m_scene->render( &painter, targetRect, sourceRect );
    25.  
    26. // move printer 1 page down
    27. sourceRect.translate( 0, pHeight );
    28.  
    29. // create new page
    30. if ( idx < pages - 1 ) {
    31. printer->newPage();
    32. }
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem on multi-pages preview with QGraphicsScene

    Anyone please?

Similar Threads

  1. Qt Multi Threading RePainting Problem
    By Mohammad in forum Qt Programming
    Replies: 4
    Last Post: 12th January 2012, 15:52
  2. Designer&Preview and MaximumSize problem
    By dresha48 in forum Qt Tools
    Replies: 0
    Last Post: 21st January 2010, 11:23
  3. Replies: 2
    Last Post: 17th May 2009, 21:58
  4. Multi-thread related problem,help me
    By mendynew in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 03:02
  5. Multi thread problem
    By sreedhar in forum Qt Programming
    Replies: 5
    Last Post: 26th June 2006, 13:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.