Reputation: 107
I've created new Qt C++ project. I want to use my printer to print out some message on a sheet of A4 paper. I am reading the documentation whole day and i can't figure out how to do this. I understood most of the things (only in the documentation), but the problem is that, that i don't know actually which of all printer libraries i should use? (PrinterDialog, qprinter, qpainter....)?
I saw all code examples, but neither one of them works.
My other question is what function should i use to check is there any ink in my printer device.
Upvotes: 3
Views: 15428
Reputation: 112
I see you already read some example codes for it, but I will pass one more to you, I hope it works (it works for me, by the way):
QPrinter printer(QPrinter::HighResolution); //create your QPrinter (don't need to be high resolution, anyway)
printer.setPageSize(QPrinter::A4);
printer.setOrientation(QPrinter::Portrait);
printer.setPageMargins (15,15,15,15,QPrinter::Millimeter);
printer.setFullPage(false);
printer.setOutputFileName("output.pdf");
printer.setOutputFormat(QPrinter::PdfFormat); //you can use native format of system usin QPrinter::NativeFormat
QPainter painter(&printer); // create a painter which will paint 'on printer'.
painter.setFont(QFont("Tahoma",8));
painter.drawText(200,200,"Test");
painter.end();
If doesn't work, test change output format to native format.
Upvotes: 7