PDA

View Full Version : Strange printing problem



porterneon
28th November 2012, 21:51
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:



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);

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?