Unsolved QPrinter with QPainter, Painting an image from qml to pdf
-
Hi i am having some difficulty painting an image with QPainter, I am calling my function from qml, my image size is A4 regular format which is an image generated from a grabToImage.
I am passing the arguments filename, and imagesourceurl (The grabtoImage result url..)
I am working in qml and i have a custom plugin that handles all my FileIO, databases, however for some reason i cant get this to work... The image size is the proper pixel size of a full A4 sheet so i am expecting the image to simply cover the area and keep things simple.
Component size is 2550x - 3300y pixels
bool FileIO::printToPDF(const QString& imgfilename, const QString& filename) { QImage img(imgfilename, Q_NULLPTR); QPrinter printer(QPrinter::HighResolution); if (filename.isEmpty()) return false; printer.setPaperSize(QPrinter::A4); printer.setFullPage(true); printer.setOutputFileName(filename + ".pdf"); printer.setOutputFormat(QPrinter::PdfFormat); QPainter paint(&printer); paint.drawImage(0,0,img); paint.end(); return true; }
I am getting a pdf document created in the correct working directory form my FileIO plugin however the document is blank... What am I missing. I cant seem to find a lot of examples on using QPrinter and QPainter
-
@arozon You should check whether img is a valid picture with http://doc.qt.io/qt-5/qimage.html#isNull