使用撤消历史记录在两个 qtextedit 或 qtextedit 和 qscintilla 之间同步内容
我正在使用 pyqt4 编写一个博客编辑器。我的问题是这样的。有一个所见即所得编辑器选项卡和一个 html 代码编辑器选项卡。其中一个方面所做的改变应该反映在另一个方面。一种选择是每当 qtextedit 中的文本发生更改时使用 setHtml 和 toHtml 函数。但这种方法的问题是,当我在 qtextedit 上使用 setHtml 时,所有先前的编辑撤消历史记录都会丢失。如果我尝试维护自己的文本更改信号历史记录,则会使用大量内存。考虑我输入一个句子,文本更改将针对每个字符发出信号,并且撤消将逐个字符进行。
我尝试在两个 qtextedit 之间共享相同的 qtextdocument,但也失败了,因为突出显示链接到 qtextdocument,因此应用于两个 qtextedit。
另一种选择是当用户在所见即所得编辑器窗口中工作时不执行任何操作。当用户在 html 代码编辑器中进行一些编辑时,我将等到用户完成编辑,然后一旦完成,我将找到编辑的差异,并以某种方式在所见即所得编辑器的 qtextdocument 中进行相应的编辑更改。这是可以实现的吗?我怎样才能在 qtextdocument 中进行这样的更改?有没有我不知道的更简单的方法?
请帮忙。
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.
我做了更多的研究,并在 Accessing QTextHtmlImporter in PyQt4 中使我的问题更清楚,
这本质上是解决这个问题。
I did a little more research and made my question more clear in Accessing QTextHtmlImporter in PyQt4
That would essentially solve this issue.