PDA

View Full Version : How to highlight differently two views of the same QTextDocument



cyr
16th May 2015, 18:34
Hello everyone !

I found already a lot of answers on this forum, but I'm stuck on this issue :

I'm trying to implement a sort of text "minimap" as we can find in Kate or Sublime Text (more the latter) .

From a single QTextDocument, I display it in a QTextEdit (editor) and also in a QTextBrowser (minimap) . The minimap uses QGraphicsView and QGrapicsProxyWidget to be seen scaled down. It works fine.

Now, I want to apply a different highlighting to each of the views. I read everywhere that I can't use two QSyntaxHighlighter in the same QTextDocument. Fine, having already use this class, I understand the limitation. Yet, I don't want to clone the QTextDocument each time there is an update, only for it to support it's own highlighter. It would be resource hungry with large texts.

Does anyone have an idea ? Maybe a workaround or a different approach ? I'd like to read your input

Thank you for your time and "Vive Qt !"

wysota
16th May 2015, 19:28
What exactly do you want to highlight differently? The whole text or do you mean selections?

cyr
16th May 2015, 19:51
Hello wysota,

A whole different set of fonts and colors for all of the document.

wysota
17th May 2015, 00:26
I'm afraid in that case you will have to make a copy of the document and synchronize both documents by handling QTextDocument::contentsChange() signal.

cyr
17th May 2015, 00:44
Thank you, I was afraid of that.