Unsolved Nicely paginate a QTextDocument
-
QTextDocument
allows to nicely render text by usingsetHtml
and then usingdrawContents
in thepaintEvent
.
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:
- 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. - Do use
QTextEdit
and set the scrollbars toScrollBarAlwaysOff
. 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!
- Go into the nitty-gritty and manually calculate the height of each