QPrinter how to print without margin
-
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 ?
-
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 ?
@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
-
@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
This post is deleted! -
This post is deleted!
@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:1183Where 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.
-
@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:1183Where 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.
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.