Good Day,
I'm perfectly printing the contents of a QTextEdit using QPrinter, but do not want to appear the page number. Has how?
Thanks,
Marcelo Geyer
Brazil
Good Day,
I'm perfectly printing the contents of a QTextEdit using QPrinter, but do not want to appear the page number. Has how?
Thanks,
Marcelo Geyer
Brazil
You can probably use QTextDocument::documentLayout() and QAbstractTextDocumentLayout::draw() to print each page yourself.
I'm not sure what example you would want. You have to pass a QPainter initialized on the printer object to the method and an empty (default) paint context object and you're done.
This has been answered elsewhere, but for those who arrive here seeking the solution, I'm reposting it: you need to set a pageSize in the document, like so:
Qt Code:
printer.setOutputFileName(fileName); QTextDocument document; document.setHtml("<p>Lorem ipsum</p>"); document.setPageSize(printer.pageRect().size()); // <-- Here is key to the solution document.print(&printer);To copy to clipboard, switch view to plain text mode
The explanation is simple, albeit not entirely intuitive. Paraphrasing @shoyeb from that thread:
When you refer the source code of print(), then you will recognize that the < QPointF pageNumberPos; > is only defined when there is no valid QTextDocument.pageSize().
In printPage() the page number only will be printed if pageNumberPos is not null.
So just set a valid QTextDocumtent.pageSize() and you'll have no page numbers on your printed document.
Bookmarks