How to paginate a QPlainTextEdit?

2019-02-20 13:45发布

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.

3条回答
趁早两清
2楼-- · 2019-02-20 14:02

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

查看更多
祖国的老花朵
3楼-- · 2019-02-20 14:06

Have a look at QTextDocument, which holds a (formatted) document that can be viewed and edited in a QTextEdit, and is page-aware.

查看更多
Lonely孤独者°
4楼-- · 2019-02-20 14:09

You can use stylesheets to modify the look-and-feel of your QPlainTextDocument like you wan want.

Hope that helps

查看更多
登录 后发表回答