PDA

View Full Version : QPrinter - rectangle coordinates



hp321
11th March 2012, 21:45
Hi. I have problem with printing rectangle with QPrinter on real device. Rectangle which I would like to draw is always cliped by a printer. Code below works great when it's export to PDF file.
What I am doing wrong? Please help me. Without this simple task I can not finish my project.


QPrinter printer;
printer.setPageSize(QPrinter::A4);
printer.setFullPage(true);
// printer.setOutputFormat(QPrinter::PdfFormat);
// printer.setOutputFileName("test.pdf");

QRectF rect = printer.pageRect();

double margin = rect.width()*0.05;

QRectF body = QRectF(margin, margin, rect.width()-margin*2, rect.height()-margin*2);

QPainter painter(&printer);
painter.drawRect(body);

QTextOption option;
option.setAlignment(Qt::AlignRight);

painter.drawText(body, "test right", option);
painter.drawText(body, "test left");

Mannion
14th March 2012, 20:26
There doesn't look like anything glaringly wrong from my perspective. I would try looking at QPrinter margin settings

void QPrinter::setPageMargins

as there may be some potential conflict with

void QPrinter::setFullPage

and tweaking your calculated margin constant of 0.05 and seeing what happens to both the pdf and the printer output.

If I wasn't working round the clock for a very crucial deadline I would spend longer on this issue. I will look back to see if I can find anything obvious.

Good Luck

wysota
14th March 2012, 20:58
Each printer has a margin where it can't print.

ChrisW67
15th March 2012, 00:21
There is at least one bug related to setFullPage() on Windows (if that is what you are using) also:
https://bugreports.qt-project.org/browse/QTBUG-5363

As far as I know it is still outstanding. This bug would cause clipping on the right and bottom of a full page sized box.