Results 1 to 5 of 5

Thread: QPrintPreviewDialog shows only blank grey area

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2013
    Posts
    14
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default Re: QPrintPreviewDialog shows only blank grey area

    No, it didn't have one set as default. I just set the XPS document printer as default and that fixed the problem. Thanks a lot!

    But is that normal behavior? If a client machine doesn't have a default printer set as mine didn't, that wouldn't be desired behavior I think? Is there a way to get around it in the code or is that what it should do?

    Thanks again!

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

    Default Re: QPrintPreviewDialog shows only blank grey area

    The problem is that the page size of a non-existent printer is zero, resulting in no visible output. If you had a printer, any printer, then the preview will always show a blank first page even if nothing is painted.

    QPrinterInfo::defaultPrinter() returns a QPrinterInfo object where QPrinterInfo::isNull() is true if there is no default printer. In that case you could use QPrintDialog or otherwise select a printer to use and then create your QPrinter object.

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

    regular (5th February 2014)

  4. #3
    Join Date
    Apr 2013
    Posts
    14
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default Re: QPrintPreviewDialog shows only blank grey area

    Sounds good, thanks again!

    EDIT: A quick note for anyone else having the problem, ussing just QPrinterInfo::isNull() didn't help because that only seems to return true if there are no printers at all on the system (and still returns false if there is no default printer set) so I had to check the printer's name too:

    Qt Code:
    1. QPrinterInfo def = QPrinterInfo::defaultPrinter();
    2.  
    3. //if there is no default printer set the print preview won't show
    4. if(def.isNull() || def.printerName().isEmpty())
    5. {
    6. if(QPrinterInfo::availablePrinters().isEmpty())
    7. {
    8. QMessageBox::critical(this, tr("Print error"), tr("Cannot proceed because there are no available printers in your system."), QMessageBox::Ok);
    9. }
    10. else
    11. {
    12. def = QPrinterInfo::availablePrinters().first();
    13. }
    14. }
    15.  
    16. QPrinter printer(def, QPrinter::ScreenResolution);
    17. .....
    To copy to clipboard, switch view to plain text mode 
    Last edited by regular; 5th February 2014 at 10:36.

Similar Threads

  1. Pratical example of QPrintPreviewDialog
    By vcp in forum Qt Programming
    Replies: 5
    Last Post: 24th July 2012, 16:24
  2. QPrintPreviewDialog.
    By cydside in forum Qt Programming
    Replies: 2
    Last Post: 19th June 2009, 17:31
  3. QPrintPreviewDialog icons
    By quipu5 in forum Qt Programming
    Replies: 0
    Last Post: 19th January 2009, 13:36
  4. Qt 4.4.0 Problem with QPrintPreviewDialog
    By ad5xj in forum Qt Programming
    Replies: 2
    Last Post: 30th May 2008, 14:01
  5. issue about blank area appear
    By cherrydou in forum Qt Programming
    Replies: 5
    Last Post: 23rd May 2008, 07:34

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
  •  
Qt is a trademark of The Qt Company.