PDA

View Full Version : QPrinter on QGraphicsScene Border Problem



patrik08
17th July 2007, 12:14
How i can leave QPrinter border / margin ? my QGraphicsScene is exact A4...
the grey part is the paper & white is margin to write...
i wand fill exact the grey part on A4..

Now here .. QPrinter display a default border i suppose...



/* XSL-FO -editor base widget */
/* http://www.zvon.org/xxl/xslfoReference/Output/index.html
<fo:simple-page-master margin-right="5pt" margin-left="5pt" margin-bottom="22pt" margin-top="22pt" page-width="21cm" page-height="29.7cm" master-name="first">
<fo:region-body/>
</fo:simple-page-master>
*/
void DisplayScene::MakefilePrintPdf()
{
QString fileName = QFileDialog::getSaveFileName(this, "Export PDF",QString(setter.value("LastDir").toString()), "*.pdf");
if (fileName.size() > 1) {
QString UserlastDirOpen = fileName.left(fileName.lastIndexOf("/"))+"/";
setter.setValue("LastDir",UserlastDirOpen);
QApplication::setOverrideCursor(QCursor(Qt::WaitCu rsor));
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
if (!fileName.endsWith(".pdf")) {
fileName = fileName+".pdf";
}
printer.setOutputFileName(fileName);
printer.setPageSize ( QPrinter::A4 );
QPainter painter(&printer);
scene->render(&painter); /* scene QGraphicsScene */
if (is_file(fileName)) {
QApplication::restoreOverrideCursor();
/* disply pdf if exist! */
OpenDesktop(QUrl(fileName));
}
}
QApplication::restoreOverrideCursor();
}

wysota
14th November 2007, 15:49
Change the viewport of the painter to the size of printable area.