September 13, 2010

icco icco
Lab Rat
4 posts

Paginating a QTextEdit

 

I am making something akin to a Word clone. As such I need a text area that displays pages as I type. The more research I do into this, the more I believe that it is impossible in Qt. Here is what I have looked at so far:

  • QTextEdit – As far as I can tell, if I want to do any sort of typing in Qt, I need to have one of these in my app.
  • QTextDocument – Everyone I talk to seems to say I do pagination with one of these. QTextEdit can give me one, but the one it returns always has a page count of one. From reading the documentation, it seems like it actually only does pagination when I try to print said document.
  • QTextFrame, QCursor, QScrollWidget, and many others – I feel like I’ve combed the entire documentation, and seen no way to actually paginate a QTextEdit. The closest I got was creating multiple QTextEdits and on text change try to redistribute the text. But this caused all kinds of problems because of the way QTextEdits paintEvent function seems to work.

Please help, in my mind this seems like it should be so simple, but everything I’ve tried leads to a deadend.

Note: This is my first time ever really using Qt, and I’m coding in Ruby.

7 replies

September 13, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

Hi Icco,

QTextEdit internally still uses the QTextDocument. There is a ready demo in Qt installation called TextEdit, that is a good place to start …qt/demos/textedit

Are you trying to show page separators?

September 13, 2010

icco icco
Lab Rat
4 posts

Yes, the main thing I am trying to do is show page separation in a QTextEdit. I’ll check out that demo, thanks.

September 13, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

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

September 13, 2010

icco icco
Lab Rat
4 posts

Oh that is cool. Thanks.

I’m finding the scene documentation kind of confusing. How do I create GraphicsItems in the correct places? Right now when I add things to the scene, they all just stack in the center. Then when I setPos, they get put in weird places.

September 13, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

To learn QGraphicsView, a very good example is the chips demo that ships with Qt …

You create a QGraphicsView, then create a QGraphicsScene, create and add QGraphicsItems to the scene (text item, or pixmap item), set position and z order if required for each of these graphics items and set the scene to the view.. that’s basically about it. Read up the API in the assistant for full set of capabilities …

January 31, 2014

Andre Andre
Robot Herder
6417 posts

Hi Icco,

Could you perhaps show how you managed to solve this? On StackExchange you say you have something that works (linking to this topic), but I don’t see an easy way to get each of the QGraphicsTextItems showing the right part of the document. Would be cool to see how this can be done.

Thanks

May 22, 2014

DOGG_11 DOGG_11
Lab Rat
1 posts

Hi Andre.

Check my implementation of paginated QTextEdit https://github.com/dimkanovikov/PagesTextEdit

 
  ‹‹ Static QFileDialog methods fail on Windows 7 Starter edition      [Moved] How to find the active GStreamer video decoder plugin instance from the Phonon GStreamer backend? ››

You must log in to post a reply. Not a member yet? Register here!