Hi
I'm using QTextEditor to format text for printing. After that I'm sending this text as html QString to print method.
On PrintButton click: emit signal_PrintFormatedText(htmlText);
Inside print method I have:
printer.
setOutputFormat(QPrinter::NativeFormat);
printer.
setDuplex(QPrinter::DuplexAuto);
printer.
setColorMode(QPrinter::GrayScale);
doc.documentLayout()->setPaintDevice(painter.device());
doc.setHtml(htmlFormatedText);
paperSize.setWidth(printer.width());
paperSize.setHeight(printer.height());
doc.setPageSize(paperSize);
doc.drawContents(&painter);
QPrinter printer;
printer.setOutputFormat(QPrinter::NativeFormat);
printer.setDuplex(QPrinter::DuplexAuto);
printer.setColorMode(QPrinter::GrayScale);
QPainter painter(&printer);
QTextDocument doc;
doc.documentLayout()->setPaintDevice(painter.device());
doc.setHtml(htmlFormatedText);
QSizeF paperSize;
paperSize.setWidth(printer.width());
paperSize.setHeight(printer.height());
doc.setPageSize(paperSize);
doc.drawContents(&painter);
To copy to clipboard, switch view to plain text mode
On first time (first printing) everything works fine. Problem is when I press PrintButton (in my app) once again. Printer prints some junk characters instead of first line of document.
What is the problem? How to fix it?
Bookmarks