Syncing content between two qtextedits with undo history
sharmila last edited by
I'm writing a cross-platform blog editor. My issue is this. There is a wysiwyg editor tab (with a QTextEdit) and a html code editor tab (again with a QTextEdit). They both should reflect the same blog content, only that they are in different modes. A change done in one should reflect in the other. One option is to use the setHtml and toHtml functions of the qtextedit objects whenever text changes in a qtextedit. But the issue with this approach is that when I use setHtml on a qtextedit, all the previous edit undo history is lost. If I try to maintain my own history on textchanged signal, lots of memory will be used. Consider I enter a sentence, textchanged will be signaled for every single character and undo would be character by character.
I tried sharing the same qtextdocument between the two qtextedits but that also failed as highlighting is linked to the qtextdocument and hence is applied to both qtextedits.
Another option is to do nothing when the user works in the wysiwyg editor window. When the user makes some edit in the html code editor, I'll wait till the user finishes the edit and then once done, I'll find the diff of the edit and somehow, make a corresponding edit change in the wysiwyg editor's qtextdocument. Is this achievable? How can I do such a change in the qtextdocument? Is there a more simple way that I am not aware of?