Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-97522

Changing printer in QPrintDialog leads to bogus page layout

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.11, 5.15.0 RC2
    • GUI: Printing
    • None
    • Windows 20H2
      msys2 3.2.0
      gcc 10.3.0
    • Windows

    Description

      I have an application that uses QPrintDialog to select a printer.  Most of the time, I can choose any printer I want, and the application prints fine.  But I found a particular printer that (if it is the default printer) causes problems with OTHER printers-specifically, they have an empty page layout of 0x0.  If the only problems were with the printer itself, I'd blame the print driver, but due to the behavior I found, I think it must be a Qt bug.

      To reproduce the bug, I set my default printer to a HP LaserJet Enterprise 700 color MFP M775 (this is important.  Several other printers do not seem to cause this problem).  Then I print in the application, but choose a different printer and click print.  If I instead click "Preferences," change nothing, but click OK, the bug does not occur.  Presumably this is because the settings have been "saved" back to Qt and override the broken values coming from the default printer.  However, it shouldn't be necessary to open preferences and change nothing-those defaults for the new printer should be loaded when you change printers.  I'm not sure what Windows exposes to Qt in terms of "unchanged" defaults, but other Windows applications seem to work ok, so there must be a solution, I'm thinking.

      Below is the code that has problems (along with a workaround).   

       printer=new QPrinter(QPrinter::HighResolution);
       printer->setPageMargins(QMarginsF(.25,.25,.25,.25), QPageLayout::Inch);
       printer->setDocName("Test");
       QPrintDialog *printDialog = new QPrintDialog(printer, this);
       if (printDialog->exec() == QDialog::Accepted) {
         if (printer->pageLayout().fullRect().width() == 0) { //qt bug when switching printers
           QPageLayout layout(QPageSize(QPageSize::Letter), QPageLayout::Portrait, QMarginsF(.25,.25,.25,.25));
           printer->setPageLayout(layout);
         }
      ...

      After the printer is created, I checked the QPrinterInfo for the default printer (HP M775).  Note the default resolution=-1, which I suspect is the source of the problem.  However, the pagelayout is entirely fine.

      QPrinterInfo(id="HP LaserJet Enterprise 700 color MFP M775 PCL6 Class Driver", state=0, makeAndModel="HP LaserJet Enterprise 700 color MFP M775 PCL6 Class Driver", default, defaultPageSize=QPageSize("Letter", key="Letter", 612x792pt, id=2), supportsCustomPageSizes, physicalPageSize=(278, 539)..(1223, 1683), defaultResolution=-1, defaultDuplexMode=0, defaultColorMode=1)
      
      QPageLayout("Letter / ANSI A", Portrait, l:0.25 r:0.25 t:0.25 b:0.25 in)
      

      After I use the print dialog to choose a different printer (Bluebeam PDF printer here, but other printers have the same issue), printer info looks ok. Note the defaultResolution is set.  But the pagelayout appears to just be a zeroed structure.

       

      QPrinterInfo(id="Bluebeam PDF", state=0, makeAndModel="BluebeamPSDriver", defaultPageSize=QPageSize("Letter", key="Letter", 612x792pt, id=2), supportsCustomPageSizes, physicalPageSize=(71, 71)..(9288, 9288), defaultResolution=600, defaultDuplexMode=0, defaultColorMode=1)
      
      QPageLayout("Custom (0pt x 0pt)", Landscape, l:0 r:0 t:0 b:0 pt)

       

      I can reproduce this issue 100% of the time, using the printer I mentioned above, and following the steps. Found the issue with 5.12, continues in 5.15.

       

       

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            johnlayt John Layt
            adipose Dan H
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes