Results 1 to 2 of 2

Thread: QPrinter - issues with page size selection (both PDF as well as real printer)

  1. #1
    Join Date
    May 2015
    Location
    Vienna
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPrinter - issues with page size selection (both PDF as well as real printer)

    Hello,

    I am experiencing issues with QPrinterDialog under Linux. Under Windows 7 and OS X (10.10), QPrinterDialog seems to work at least better (I still need to give it a thorough test, but at first, it looks OK)

    CODE:

    Qt Code:
    1. QPrinter printer;
    2.  
    3. printer.setOutputFormat(QPrinter::PdfFormat);
    4. printer.setPaperSize(QPrinter::A2);
    5. QPrintDialog dialog(&printer, this);
    To copy to clipboard, switch view to plain text mode 

    PDF:

    1. The preselected printer is not the PDF, but rather the real printer, as defined by CUPS. Due to the first line, I'd expect the PDF to be pre-selected.
    2. If I now select the PDF printer in the dialog, and open the "Properties" window, the paper size drop-down is empty. In the "width / height" fields, however, the correct size of the A2 paper is showing, and the output will be of the correct size A2.
    3. If I open the drop-down menu, the list of possible sizes show, but regardless of what I select, the (now closed) menu is empty, and the size which is showing in the dialog is A4. The output size is A4.

    REAL PRINTER:

    1. Upon opening the dialog, the paper size drop-down menu is empty, which is understandable, because my printer doesn't support A2. HOWEVER, the paper width / height shown in the dialog do correspond to A2
    2. Opening the drop down menu shows a billion paper size options (way more than, say, under OS X for the same printer), all of them look selectable, but only some of them actually are. For example, "Photo 4x6in" is supported by my printer, but selecting it drops me back to what was previously selected, if that previous selection was correct.

    Under OSX, none of the above problems seem to occur (the same code), except that I can't set the PDF as output format ("non native" or something, on OS X, printing into PDF seems to work a bit differently, I'm still an apple newbie)

    I hope this explanation is making some sense!


    Here the complete code, although only the section above is relevant:

    Qt Code:
    1. void MainWindow::on_actionPrint_triggered()
    2. {
    3. QPrinter printer;
    4.  
    5. printer.setOutputFormat(QPrinter::PdfFormat);
    6. printer.setPaperSize(QPrinter::A2); // Default for the print dialog
    7. QPrintDialog dialog(&printer, this);
    8.  
    9. dialog.setWindowTitle(tr("Print Document"));
    10.  
    11. if (dialog.exec() == QDialog::Accepted)
    12. {
    13. pp.begin(&printer);
    14. QPagedPaintDevice::Margins margins = printer.margins();
    15. int logicalHeight, logicalWidth;
    16. std::cout << "paper width: " << printer.pageSizeMM().width() << " paper height: " << printer.pageSizeMM().height() << std::endl;
    17.  
    18. if (printer.orientation() == QPrinter::Portrait)
    19. {
    20. logicalWidth = printer.pageSizeMM().width() - (margins.left + margins.right);
    21. logicalHeight = printer.pageSizeMM().height()- (margins.top + margins.bottom);
    22. }
    23. else
    24. {
    25. logicalWidth = printer.pageSizeMM().height() - (margins.left + margins.right);
    26. logicalHeight = printer.pageSizeMM().width() - (margins.top + margins.bottom);
    27. }
    28.  
    29. int physicalWidth = printer.width();
    30. int physicalHeight = printer.height();
    31.  
    32. pp.setWindow(0, 0, logicalWidth, logicalHeight);
    33. pp.setViewport(0, 0, physicalWidth, physicalHeight);
    34. pp.drawRect(0, 0, logicalWidth, logicalHeight); // Drawing extents
    35.  
    36. QFont font("Courier", 3); // Seems this "3" is already in mm...
    37. pp.setFont(font);
    38. pp.drawText(QPointF(40, 40), "Hello, World 3!");
    39. font.setPointSize(4); // And this "4" too! :)
    40. pp.setFont(font);
    41. pp.drawText(QPointF(80, 40), "Hello, World 4!");
    42.  
    43. pp.drawRect(50, 50, 100, 100);
    44. pp.end();
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 


    Added after 6 minutes:


    Sorry, forgot to mention: QT 5.4.0, Linux Ubuntu 14.04.2 LTS.


    Added after 43 minutes:


    Now also tried with 5.4.1 - still the same.
    Last edited by sir_clive; 27th May 2015 at 02:23.

  2. #2
    Join Date
    May 2015
    Location
    Vienna
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPrinter - issues with page size selection (both PDF as well as real printer)

    Funny that nobody experienced the same problem.

    For a multi-OS environment, with some "special requirements" with respect to printing, it seems that QPrintDialog is not really useable. OS X completely ignores options (I know that's documented, but it's not a solution for me, I have to disable some options), under Ubuntu, I have the aforementioned problems. The list of supported page formats contains some 30 occurrences of code "30" ("Custom or unknown"), there is no way to set the filter which paper sizes are allowed, ... I haven't tested on Windows since the last time, so I can't say much about it.

    I understand that QPrintDialog tries to use the native print dialog for printing, but that introduces some bad headaches if a program needs to run on more than just one platform.

    I LOVE QT, it works nearly perfect for everything else, but printing seems not to be among its' greatest strengths. I'm afraid I'll just need to implement my own printer dialog (not derived from QAbstractPrintDialog). It's a pity!

Similar Threads

  1. How do I set a custom page/paper size in QPrinter
    By alferjaani in forum Qt Programming
    Replies: 7
    Last Post: 26th July 2013, 04:42
  2. Replies: 0
    Last Post: 30th May 2013, 10:19
  3. QPainter problem with real printer on linux
    By corossig in forum Qt Programming
    Replies: 0
    Last Post: 22nd February 2012, 14:47
  4. how to send printer commands using QPrinter?
    By cutie.monkey in forum Qt Programming
    Replies: 1
    Last Post: 23rd April 2010, 09:19
  5. printer the chinese character with QPrinter
    By trytoremeber963 in forum Qt Programming
    Replies: 0
    Last Post: 3rd June 2008, 08:42

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.