Add custom text wrap logic to QPlainTextEdit
Is there a way to add a custom text wrap logic to a
QPlainTextEdit, maybe extending it or any of its related classes?
My goal is to create a simple text editor for my students to implement a Dynamic Programming algorithm for laying text on a canvas. As it should be simple, I'm hoping there is a simple solution to this problem.
In short, I will receive a list of valid cursor positions in which the editor is supposed to visually break the lines.
I already read a little about
QTextLayoutand the likes, but I could not find by myself where to put the custom logic on.
Another way to put this: How do I inject a custom
Apparently it is virtually impossible to do what I want because the
QTextBlockitself hardcodes a
::layout()method (see here). Moreover, it seems that every hook we could use is only available in the private classes...
Now, the problem is that it prevents everybody wanting to implement custom behavior to create anything based on the
QTextDocumentand its associates. I wonder how the people who created text editors got away with this (probably implemented everything from scratch).
Well, at the end, the only thing I found that could work was to manually insert unicode
U+002028(Line Separator) wherever I want using
QTextCursor, which is terrible because everytime the editor area width changes I have to remove the old ones and insert new ones...
As I'm not happy with the solution I found, I'll not mark this question as solved.