Results 1 to 5 of 5

Thread: print preview

  1. #1
    Join Date
    Sep 2006
    Posts
    9
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default print preview

    I use the QPrintPreviewDialog with no problem.

    1) Is it normal that after pressing the print button print dialog, the Print Preview also closes?

    2) When choosing what pages to print in the print dialog, it still prints from the beginning or from page 1.

    Are these bugs in the QPrintPreviewDialog?

    Thank you.

    Wilbert

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: print preview

    Quote Originally Posted by wbt_ph View Post
    1) Is it normal that after pressing the print button print dialog, the Print Preview also closes?
    AFAICT that is normal operation.
    2) When choosing what pages to print in the print dialog, it still prints from the beginning or from page 1.
    You need to fetch and use the fromPage(), toPage(), and numCopies() values from your QPrinter (passed into paintRequested()) and do something like:
    Qt Code:
    1. void MyClass::printPages(QPainter *painter)
    2. {
    3. int firstPage = m_printer->fromPage() - 1;
    4. if (firstPage >= m_pages.size())
    5. return;
    6. if (firstPage == -1)
    7. firstPage = 0;
    8. int lastPage = m_printer->toPage() - 1;
    9. if (lastPage == -1 || lastPage >= m_pages.size())
    10. lastPage = m_pages.size() - 1;
    11. int numPages = lastPage - firstPage + 1;
    12. for (int i = 0; i < m_printer->numCopies(); ++i) {
    13. for (int j = 0; j < numPages; ++j) {
    14. if (i != 0 || j != 0)
    15. m_printer->newPage();
    16. int index;
    17. if (m_printer->pageOrder() == QPrinter::FirstPageFirst) {
    18. index = firstPage + j;
    19. } else {
    20. index = lastPage - j;
    21. }
    22. printPage(painter, m_pages.at(index), index + 1);
    23. }
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 
    (m_pages is a list of pagination data I have built). This code is from "C++ GUI Programming with QT4", Blanchette and Summerfield, 2008.

    Are these bugs in the QPrintPreviewDialog?
    No, I don't think so.

  3. The following user says thank you to ChrisW67 for this useful post:

    wbt_ph (28th July 2009)

  4. #3
    Join Date
    Sep 2006
    Posts
    9
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: print preview

    Chrisw67:

    Thank you for your reply.

    If closing the print dialog (which also closes the print preview dialog) is normal, how can you programatically change the closing of print to dialog so it does not close the print preview dialog?

    If you have to get the page ranges from qprinter, do you have to repaint or redisplay print preview dialog again?

    Wilbert

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: print preview

    Sorry, been off maintaining a VB6 monstrosity for a few days...
    If closing the print dialog (which also closes the print preview dialog) is normal, how can you programatically change the closing of print to dialog so it does not close the print preview dialog?
    This behaviour is fairly normal when you press Print in a preview even in non-Qt circles. I think to get other behaviour you will have to make your own print preview dialog using QPrintPreviewWidget.
    If you have to get the page ranges from qprinter, do you have to repaint or redisplay print preview dialog again?
    The Qt code will call paintRequested() as required. In my experience, it gets called once when the dialog is first created (all pages), and once when Print is pressed: different printer object each time, and potentially different from/to page if that's what the user requests on the way through the QPrintDialog.

  6. The following user says thank you to ChrisW67 for this useful post:

    wbt_ph (1st August 2009)

  7. #5
    Join Date
    Sep 2006
    Posts
    9
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: print preview

    ChrisW67:

    Thank you for your help.

    Wilbert

Similar Threads

  1. Trouble to print with QPrintPreviewWidget
    By estanisgeyer in forum Qt Programming
    Replies: 5
    Last Post: 24th December 2009, 06:14
  2. Change margin on QTextEdit print()
    By Dii in forum Qt Programming
    Replies: 2
    Last Post: 20th May 2008, 22:45
  3. Audio/Video Preview on Windows?
    By vishal.chauhan in forum Qt Programming
    Replies: 0
    Last Post: 2nd May 2008, 06:10
  4. preview file dialog
    By mickey in forum Qt Programming
    Replies: 11
    Last Post: 21st April 2006, 23:03
  5. Replies: 4
    Last Post: 24th March 2006, 22:50

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.