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");
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");