Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPrinter orientation problem
Forum Updated to NodeBB v4.3 + New Features

QPrinter orientation problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 712 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MartinGU
    wrote on last edited by
    #1

    I have to simulate a label printer (I don't have access to the printer right now), and QPrinter reverses the orientation.

    I'm selecting printer by looping through printers in the system and selecting the printer that has the name I want to print to:

    QString sPrinter = "PDFCreator";
    QList<QPrinterInfo> printerList=QPrinterInfo::availablePrinters();
    foreach (QPrinterInfo printerInfo, printerList) {
        if (printerInfo.printerName() == sPrinter) {
           ...
    

    After finding my printer I check the width/height of the printer using:

    QPageSize ps = printerInfo.defaultPageSize();
    
    int width = ps.size(QPageSize::Millimeter).width();
    int height = ps.size(QPageSize::Millimeter).height();
    

    width is 80 mm, height is 800 mm
    just as it set in windows.

    I then do:

    QPrinter printer = new QPrinter(printerInfo, QPrinter::HighResolution);
    QPageLayout pla = printer->pageLayout();
    int new_width = pla.fullRect(QPageLayout::Millimeter).width();
    int new_height = pla.fullRect(QPageLayout::Millimeter).height();
    

    However now new_width is 800 mm and new_height is 80 mm, that is the orientation has changed!

    I need to know the paper width since I must support both label printer and A4 formats.

    I tried printing to this printer from other applications (Chrome, Notepad, Windows printer test) and they give the right result.

    Is this to be expected?? Or is this a bug??

    QT opensource 6.4.2 Windows 10, MinGW.
    Printer is PDFCreator 5.0.3 by PDFforge.
    Setting in Windows Printing preferences, Advanced, Paper Size,
    Postscript Custom Page Size Definition, Width: 80mm, Height 800mm, this is to simulate a label printer.
    
    JoeCFDJ 1 Reply Last reply
    0
    • M MartinGU

      I have to simulate a label printer (I don't have access to the printer right now), and QPrinter reverses the orientation.

      I'm selecting printer by looping through printers in the system and selecting the printer that has the name I want to print to:

      QString sPrinter = "PDFCreator";
      QList<QPrinterInfo> printerList=QPrinterInfo::availablePrinters();
      foreach (QPrinterInfo printerInfo, printerList) {
          if (printerInfo.printerName() == sPrinter) {
             ...
      

      After finding my printer I check the width/height of the printer using:

      QPageSize ps = printerInfo.defaultPageSize();
      
      int width = ps.size(QPageSize::Millimeter).width();
      int height = ps.size(QPageSize::Millimeter).height();
      

      width is 80 mm, height is 800 mm
      just as it set in windows.

      I then do:

      QPrinter printer = new QPrinter(printerInfo, QPrinter::HighResolution);
      QPageLayout pla = printer->pageLayout();
      int new_width = pla.fullRect(QPageLayout::Millimeter).width();
      int new_height = pla.fullRect(QPageLayout::Millimeter).height();
      

      However now new_width is 800 mm and new_height is 80 mm, that is the orientation has changed!

      I need to know the paper width since I must support both label printer and A4 formats.

      I tried printing to this printer from other applications (Chrome, Notepad, Windows printer test) and they give the right result.

      Is this to be expected?? Or is this a bug??

      QT opensource 6.4.2 Windows 10, MinGW.
      Printer is PDFCreator 5.0.3 by PDFforge.
      Setting in Windows Printing preferences, Advanced, Paper Size,
      Postscript Custom Page Size Definition, Width: 80mm, Height 800mm, this is to simulate a label printer.
      
      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      @MartinGU
      can you try to set this?
      bool QPrinter::setPageOrientation(QPageLayout::Orientation orientation)
      https://doc.qt.io/qt-5.15/qprinter.html#setPageOrientation

      M 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @MartinGU
        can you try to set this?
        bool QPrinter::setPageOrientation(QPageLayout::Orientation orientation)
        https://doc.qt.io/qt-5.15/qprinter.html#setPageOrientation

        M Offline
        M Offline
        MartinGU
        wrote on last edited by MartinGU
        #3

        @JoeCFD
        I added:

         printer->setPageOrientation(QPageLayout::Portrait);
        
        

        And now it prints in Landscape!!!

        So no, did not help...

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved