views:

39

answers:

3

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.

A: 

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

Fred
I can paginate the text, that's not the issue. The issue is how do I make a single QTextEdit look like a set of pages instead of a gigantic text field, if that makes sense. I've reworded my question to make more sense.
icco
I see, that's an interesting scenario. Are you willing to dive into Qt's code or are you looking for something that works out of the box?
Fred
Something out of box preferably. This is a pretty small ruby app, so having to include a custom compile of the C++ libraries would be a pita. I'd be willing to implement my own version of QTextEdit I guess, although I am a Qt newb in most regards, so I'd prefer to avoid that if possible.
icco
A: 

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

Hope that helps

Patrice Bernassola
I've used style sheets on UI elements, but I don't seem to understand how I would style the actual document. That just doesn't make sense to me.
icco
Try to play with background and borders to modify the render of the widget to look like a piece of paper
Patrice Bernassola
A: 

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

icco