I have a QPlainTextEdit widget that holds text that the user entered. The text might contain \n characters or it may all be on one very long line. My objective is to print this text on a printer (on paper) with word wrapping. The functions QPlainTextEdit::print() and QTextDocument::print() are not suitable to me because they both print the page number at the bottom of the page, which I don't want, and second, I can't seem to be able to control which pages to print (for example if the user only wants to print page #2 out of 5 pages) - the entire document is always printed.
Basically I am using a QPainter object to paint the text on the printer. The main difficulty I am facing is determining when to call QPrinter::newPage() function. How do you determine how much text will fit on a page? If the text is on one long line and the line is being word wrapped, how do you know when the first page is full and when to start a second page? I use the following code to draw:
painter.drawText(printer->pageRect(), Qt::TextWordWrap, ui->plainTextEdit->toPlainText());
painter is of type QPainter; printer is of type QPrinter; plainTextEdit is of type QPlainTextEdit.