How to paginate a QPlainTextEdit?

南楼画角 提交于 2019-12-01 12:32:44

问题


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.


回答1:


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




回答2:


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:


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

Hope that helps



来源:https://stackoverflow.com/questions/3605368/how-to-paginate-a-qplaintextedit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!