Commit a83259e9 authored by Taneli Peltoniemi's avatar Taneli Peltoniemi
Browse files

Changed the print function so that it doesn't continue if item is null.

The view also resizes now according to the resolution we get from the printer object.
parent b26793f2
......@@ -20,6 +20,9 @@ QmlPrinter::~QmlPrinter()
void QmlPrinter::printPDF(const QString &location, QQuickItem *item, bool showPDF)
{
if(!item)
return;
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(location);
......@@ -30,6 +33,10 @@ void QmlPrinter::printPDF(const QString &location, QQuickItem *item, bool showPD
printer.setOrientation(QPrinter::Portrait);
printer.setPaperSize(QPrinter::A4);
// Resizes the root object to the resolution that the printer uses for printable area
item->setProperty("width", printer.pageRect().width());
item->setProperty("height", printer.pageRect().height());
QPainter painter;
painter.begin(&printer);
paintItem(item, item->window(), &painter);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment