问题
I'm using QTextEdit from C++ Qt5. I want to properly split and show rich text in numerated pages similarly to how it's done in Microsoft Word. I've tried document->setPageSize
, however that does not work for me - text is still shown in one continuous page.
回答1:
AFAIK QTextEdit doesn't support the word-processor-style concept of "pages". Rather, QTextEdit is designed around editing and viewing a continuous document, whose only delineation is at the level of "blocks" (i.e. paragraphs).
Note this telling comment in the QTextDocument::print(QPagedPaintDevice *) const
method-documentation of the QTextDocument class:
If the document is not paginated, like for example a document used in a QTextEdit, then a temporary copy of the document is created and the copy is broken into multiple pages according to the size of the paint device's paperRect().
来源:https://stackoverflow.com/questions/61840370/how-to-split-qtextedit-into-pages