Search code examples
qtqt4paginationqtruby

How to paginate a QPlainTextEdit?


I've been using QPlainTextEdit for editing text in our application. Recently it was decided that we need to display the text in a paginated format instead of a consistent block of text. After lots of research, I've come to the realization that while QPlainTextEdit does not have any knowledge of pages or pagination, QPlainTextDocument does.

It sounds like internally we want to be doing the pagination, but what I can't figure out is how to modify QPlainTextEdit to show the text in pages instead of a gigantic field.

Side note: I know it doesn't matter but I am using qtruby, not plain Qt.


Solution

  • I ended up re-asking this on the Qt forums: http://developer.qt.nokia.com/forums/viewthread/862

    They gave me a decent idea which has worked pretty well:

    If you want like the page layout in word, one way I see is … using QGraphicsView, setting the scene, setting multiple QGraphicsTextItems which are editable, and updating the entire text on any edits.. you can set QTextDocument to these text items ..

    Something similar is also available if you refer the QPrintPreviewWidget source