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 how to print without margin
Forum Updated to NodeBB v4.3 + New Features

QPrinter how to print without margin

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 708 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.
  • S Offline
    S Offline
    Stormbringer1900
    wrote on last edited by Stormbringer1900
    #1

    I have the printer Canon SELPHY CP1200 than permit to print photos without margin.

    I have install the driver with CUPS (from snap).

    When I print a jpg file in good format with lpr command, the rendering is well : without margin.

    But when I use this code :

        QPrinter printer(QPrinter::PrinterResolution);
        printer.setDocName(title);
        printer.setColorMode(QPrinter::Color);
        printer.setPaperSource(QPrinter::Auto);
        printer.setPageOrientation(QPageLayout::Landscape);
        printer.setResolution(300);
        printer.setFullPage(true);
        printer.setPageSize(QPageSize::Postcard);
        printer.setFullPage(true);
        printer.setPageMargins(QMarginsF(0, 0, 0, 0), QPageLayout::Millimeter);
    
        QImage img(imgFilename);
        QPainter painter(&printer);
        painter.drawImage(QPoint(0,0),img);
    
        painter.end();
    

    This same image (well printed with lpr) is print in full dimension of the paper, but margins crop the image.

    I don't know how to remove these margins.

    To complete : When I modify the code to print this image in a PDF, there's no problem.

    Any idea ?

    C 1 Reply Last reply
    0
    • S Stormbringer1900

      I have the printer Canon SELPHY CP1200 than permit to print photos without margin.

      I have install the driver with CUPS (from snap).

      When I print a jpg file in good format with lpr command, the rendering is well : without margin.

      But when I use this code :

          QPrinter printer(QPrinter::PrinterResolution);
          printer.setDocName(title);
          printer.setColorMode(QPrinter::Color);
          printer.setPaperSource(QPrinter::Auto);
          printer.setPageOrientation(QPageLayout::Landscape);
          printer.setResolution(300);
          printer.setFullPage(true);
          printer.setPageSize(QPageSize::Postcard);
          printer.setFullPage(true);
          printer.setPageMargins(QMarginsF(0, 0, 0, 0), QPageLayout::Millimeter);
      
          QImage img(imgFilename);
          QPainter painter(&printer);
          painter.drawImage(QPoint(0,0),img);
      
          painter.end();
      

      This same image (well printed with lpr) is print in full dimension of the paper, but margins crop the image.

      I don't know how to remove these margins.

      To complete : When I modify the code to print this image in a PDF, there's no problem.

      Any idea ?

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      @Stormbringer1900 What are pageRect() and paperRect() either side of the setPageMargins() call?
      What version of Qt?

      Seems somewhat like, but not the same as, QTBUG-5363

      S 1 Reply Last reply
      0
      • C ChrisW67

        @Stormbringer1900 What are pageRect() and paperRect() either side of the setPageMargins() call?
        What version of Qt?

        Seems somewhat like, but not the same as, QTBUG-5363

        S Offline
        S Offline
        Stormbringer1900
        wrote on last edited by
        #3
        This post is deleted!
        C 1 Reply Last reply
        0
        • S Stormbringer1900

          This post is deleted!

          C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          @Stormbringer1900 said in QPrinter how to print without margin:

          Page Rect (deprecated) -> l:0, t:0, r:0, b:0, w:0, h:0
          Paper Rect (deprecated) -> l:0, t:0, r:0, b:0, w:0, h:0
          Page Layout fullRectPixels(300) -> l:0, t:0, r:1746, b:1183, w:1746, h:1183
          

          Where do you get deprecated from? Qt 6 has a version of both functions taking a units argument and returning a QRectF. I would expect something other than zeroes here. The pixel size in the last row would indicate that the Postcard size is 5.82" wide 3.94" high (148 by 100mm): does that agree with your expectation?

          Physical printers often have small unprintable borders but I would expect these to apply uniformly.

          S 1 Reply Last reply
          0
          • C ChrisW67

            @Stormbringer1900 said in QPrinter how to print without margin:

            Page Rect (deprecated) -> l:0, t:0, r:0, b:0, w:0, h:0
            Paper Rect (deprecated) -> l:0, t:0, r:0, b:0, w:0, h:0
            Page Layout fullRectPixels(300) -> l:0, t:0, r:1746, b:1183, w:1746, h:1183
            

            Where do you get deprecated from? Qt 6 has a version of both functions taking a units argument and returning a QRectF. I would expect something other than zeroes here. The pixel size in the last row would indicate that the Postcard size is 5.82" wide 3.94" high (148 by 100mm): does that agree with your expectation?

            Physical printers often have small unprintable borders but I would expect these to apply uniformly.

            S Offline
            S Offline
            Stormbringer1900
            wrote on last edited by Stormbringer1900
            #5

            About the deprecation it's after Qt 5.15 on QPrinter's methods pageRect and paperRect.

            About the zeros, I have retry, I think it's an error. Please ignore my previous comment.

            I've no time now to retry, but I will do that later.

            Thank's.

            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