Qt How to print information via QPrinter?

最后都变了- 提交于 2020-01-24 01:30:09

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/18660137/qt-how-to-print-information-via-qprinter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!