syncing content between two qtextedits or a qtextedit and qscintilla with undo history

551 views Asked by At

I'm writing a blog editor using pyqt4. My issue is this. There is a wysiwyg editor tab and a html code editor tab. A change done in one should reflect in the other. One option is to use the setHtml and toHtml functions 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?

Please help.

1

There are 1 answers

0
Sharmila On BEST ANSWER

I did a little more research and made my question more clear in Accessing QTextHtmlImporter in PyQt4

That would essentially solve this issue.