PDA

View Full Version : highlight in QTextEdit



ubuntudevelop78
26th November 2009, 23:45
Hello,

I am not using QSyntaxHighlight because I don't know how to use it and my Highlighter works very well but it is the problem it is too slow :crying:, I am trying to highlight my own programming language.

The question is how to get only the part of the String that will be rendered to the user, that will help me a lot because the program only needs to get tokens and replaces a part of the string, my string is too long because I need to encode each token with a long string that QRegExp in QString relace could ignore to find the other tokens without interfering.

I think QTextEdit uses it internally because when the user scroll down the text it will need to know a starting line and end line to be drawn maybe in it's paint event or something, in that widget, because the text could be greater than the QTextEdit area and the scroll position can change, I am using QT Creator in ubuntu.

Thank you

Regards.

wysota
27th November 2009, 00:22
It will be easier to do it using QPlainTextEdit. You can use QPlainTextEdit::firstVisibleBlock() to get the first block. As for the last block it is probably easiest to compute it knowing the height of the viewport and font metrics of the font used in the document. Anyway, if you are highlighting your text by introducing html tags into the text of the document, I suggest you don't do that. It's much better and easier to do it using QSyntaxHighlighter.