Search code examples
qtqtgui

Highlight odd lines with QSyntaxHighlighter


As far as I know, I have to inherit from QSyntaxHighlighter and and override highlightBlock() to make a highlighter for my QTextEdit.

However, I can only get a QString in highlightBlock(). The string does not contain any information about where it is in that document. How can I do if I want to highlight the text only in odd lines of the document?


Solution

  • QSyntaxHighlighter has this

    protected:
    QTextBlock currentBlock() const;
    

    where you can find blockNumber()