Hello,
I'm porting an application to Qt4.2 from Qt3.
Application needs to highlight a given range of lines in a QTextEdit, as example from line 5 to line 12.
With Q3SyntaxHighlighter I use currentParagraph() inside highlightParagraph() to read current line and set highlight accordingly with setFormat().
Sadly, I cannot find a way to read current block number with the new QSyntaxHighlighter. So how can I know what is the block is currently passed to the highlightBlock() callback?
The best I have found is an ugly trick using block state. At the beginning of my reimplementation of highlightBlock() I write:
virtual void highlightBlock(const QString& p) {
// state is used to count paragraphs, staring from 0
setCurrentBlockState(previousBlockState() + 1);
and then I fake the current paragraph info with currentBlockState()
Is it correct? there is a better way?
Thanks
Marco
Bookmarks