Important: Please read the Qt Code of Conduct -

Nicely paginate a QTextDocument

  • QTextDocument allows to nicely render text by using setHtml and then using drawContents in the paintEvent.
    What completely eludes me, after having read almost all the concerning docs , is how to avoid the ugly cutoff when the rendered text overshoots.
    QTextEdit, or any of its superclasses, is not a solution because it brings with it the scrollbar(s) which I really don't want. Instead the user should be able to paginate through the document, for example by using the arrow keys (on the desktop) or by tapping (on a device with a touchscreen).

    So far I have explored two approaches:

    1. Go into the nitty-gritty and manually calculate the height of each QTextBlock, see here for a failed attempt (the height calculation doesn't work on blocks that span more than one line). No correct solution has transpired, so far.
    2. Do use QTextEditand set the scrollbars to ScrollBarAlwaysOff. Then somehow make it not overspill. Then make it paginate nicely.

    It seems like the machinery to do this is there, after all for printing it's necessary to paginate. So there must be a mechanism.

    Any hints on how to approach this would be greatly appreciated!

Log in to reply