<class name="QSyntaxHighlighter" doc="/**
&lt;p&gt;The &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt; class allows you to define syntax highlighting rules, and in addition you can use the class to query a document's current formatting or user data.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt; class is a base class for implementing &lt;a href=&quot;QTextEdit.html&quot;&gt;&lt;tt&gt;QTextEdit&lt;/tt&gt;&lt;/a&gt; syntax highlighters. A syntax highligher automatically highlights parts of the text in a &lt;a href=&quot;QTextEdit.html&quot;&gt;&lt;tt&gt;QTextEdit&lt;/tt&gt;&lt;/a&gt;, or more generally in a &lt;a href=&quot;QTextDocument.html&quot;&gt;&lt;tt&gt;QTextDocument&lt;/tt&gt;&lt;/a&gt;. Syntax highlighters are often used when the user is entering text in a specific format (for example source code) and help the user to read the text and identify syntax errors.&lt;/p&gt;
&lt;p&gt;To provide your own syntax highlighting, you must subclass &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt; and reimplement &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;When you create an instance of your &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt; subclass, pass it the &lt;a href=&quot;QTextEdit.html&quot;&gt;&lt;tt&gt;QTextEdit&lt;/tt&gt;&lt;/a&gt; or &lt;a href=&quot;QTextDocument.html&quot;&gt;&lt;tt&gt;QTextDocument&lt;/tt&gt;&lt;/a&gt; that you want the syntax highlighting to be applied to. For example:&lt;/p&gt;
&lt;pre&gt;    QTextEdit *editor = new QTextEdit;
    MyHighlighter *highlighter = new MyHighlighter(editor-&amp;gt;document());&lt;/pre&gt;
&lt;p&gt;After this your &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt; function will be called automatically whenever necessary. Use your &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt; function to apply formatting (e.g&amp;#x2e; setting the font and color) to the text that is passed to it. &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt; provides the &lt;a href=&quot;QSyntaxHighlighter.html#setFormat(int, int, com.trolltech.qt.gui.QColor)&quot;&gt;&lt;tt&gt;setFormat&lt;/tt&gt;&lt;/a&gt; function which applies a given &lt;a href=&quot;QTextCharFormat.html&quot;&gt;&lt;tt&gt;QTextCharFormat&lt;/tt&gt;&lt;/a&gt; on the current text block. For example:&lt;/p&gt;
&lt;pre&gt;    void MyHighlighter::highlightBlock(const QString &amp;amp;text)
    {
        QTextCharFormat myClassFormat;
        myClassFormat.setFontWeight(QFont::Bold);
        myClassFormat.setForeground(Qt::darkMagenta);
        QString pattern = &amp;quot;\\bMy[A-Za-z]+\\b&amp;quot;;

        QRegExp expression(pattern);
        int index = text.indexOf(expression);
        while (index &amp;gt;= 0) {
            int length = expression.matchedLength();
            setFormat(index, length, myClassFormat);
            index = text.indexOf(expression, index + length);
         }
     }&lt;/pre&gt;
&lt;p&gt;Some syntaxes can have constructs that span several text blocks. For example, a C++ syntax highlighter should be able to cope with &lt;tt&gt;/&lt;/tt&gt;&lt;tt&gt;*...*&lt;/tt&gt;&lt;tt&gt;/&lt;/tt&gt; multiline comments. To deal with these cases it is necessary to know the end state of the previous text block (e.g&amp;#x2e; &amp;quot;in comment&amp;quot;).&lt;/p&gt;
&lt;p&gt;Inside your &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt; implementation you can query the end state of the previous text block using the &lt;a href=&quot;QSyntaxHighlighter.html#previousBlockState()&quot;&gt;&lt;tt&gt;previousBlockState&lt;/tt&gt;&lt;/a&gt; function. After parsing the block you can save the last state using &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockState(int)&quot;&gt;&lt;tt&gt;setCurrentBlockState&lt;/tt&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;QSyntaxHighlighter.html#currentBlockState()&quot;&gt;&lt;tt&gt;currentBlockState&lt;/tt&gt;&lt;/a&gt; and &lt;a href=&quot;QSyntaxHighlighter.html#previousBlockState()&quot;&gt;&lt;tt&gt;previousBlockState&lt;/tt&gt;&lt;/a&gt; functions return an int value. If no state is set, the returned value is -1. You can designate any other value to identify any given state using the &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockState(int)&quot;&gt;&lt;tt&gt;setCurrentBlockState&lt;/tt&gt;&lt;/a&gt; function. Once the state is set the &lt;a href=&quot;QTextBlock.html&quot;&gt;&lt;tt&gt;QTextBlock&lt;/tt&gt;&lt;/a&gt; keeps that value until it is set set again or until the corresponding paragraph of text is deleted.&lt;/p&gt;
&lt;p&gt;For example, if you're writing a simple C++ syntax highlighter, you might designate 1 to signify &amp;quot;in comment&amp;quot;:&lt;/p&gt;
&lt;pre&gt;    QTextCharFormat multiLineCommentFormat;
    multiLineCommentFormat.setForeground(Qt::red);

    QRegExp startExpression(&amp;quot;/\\*&amp;quot;);
    QRegExp endExpression(&amp;quot;\\* /&amp;quot;);

    setCurrentBlockState(0);

    int startIndex = 0;
    if (previousBlockState() != 1)
        startIndex = text.indexOf(startExpression);

    while (startIndex &amp;gt;= 0) {
       int endIndex = text.indexOf(endExpression, startIndex);
       int commentLength;
       if (endIndex == -1) {
           setCurrentBlockState(1);
           commentLength = text.length() - startIndex;
       } else {
           commentLength = endIndex - startIndex
                           + endExpression.matchedLength();
       }
       setFormat(startIndex, commentLength, multiLineCommentFormat);
       startIndex = text.indexOf(startExpression,
                                 startIndex + commentLength);
    }&lt;/pre&gt;
&lt;p&gt;In the example above, we first set the current block state to 0. Then, if the previous block ended within a comment, we higlight from the beginning of the current block (&lt;tt&gt;startIndex = 0&lt;/tt&gt;). Otherwise, we search for the given start expression. If the specified end expression cannot be found in the text block, we change the current block state by calling &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockState(int)&quot;&gt;&lt;tt&gt;setCurrentBlockState&lt;/tt&gt;&lt;/a&gt;, and make sure that the rest of the block is higlighted.&lt;/p&gt;
&lt;p&gt;In addition you can query the current formatting and user data using the &lt;a href=&quot;QSyntaxHighlighter.html#format(int)&quot;&gt;&lt;tt&gt;format&lt;/tt&gt;&lt;/a&gt; and &lt;a href=&quot;QSyntaxHighlighter.html#currentBlockUserData()&quot;&gt;&lt;tt&gt;currentBlockUserData&lt;/tt&gt;&lt;/a&gt; functions respectively. You can also attach user data to the current text block using the &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockUserData(com.trolltech.qt.gui.QTextBlockUserData)&quot;&gt;&lt;tt&gt;setCurrentBlockUserData&lt;/tt&gt;&lt;/a&gt; function. &lt;a href=&quot;QTextBlockUserData.html&quot;&gt;&lt;tt&gt;QTextBlockUserData&lt;/tt&gt;&lt;/a&gt; can be used to store custom settings. In the case of syntax highlighting, it is in particular interesting as cache storage for information that you may figure out while parsing the paragraph's text. For an example, see the &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockUserData(com.trolltech.qt.gui.QTextBlockUserData)&quot;&gt;&lt;tt&gt;setCurrentBlockUserData&lt;/tt&gt;&lt;/a&gt; documentation.&lt;/p&gt;

@see &lt;a href=&quot;QTextEdit.html&quot;&gt;&lt;tt&gt;QTextEdit&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;%2E%2E/qtjambi-syntaxhighlighter.html&quot;&gt;Syntax Highlighter Example&lt;/tt&gt;&lt;/a&gt; */">
    <method name="public QSyntaxHighlighter(com.trolltech.qt.core.QObject parent)" doc="/**
&lt;p&gt;Constructs a &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt; with the given &lt;tt&gt;parent&lt;/tt&gt;.&lt;/p&gt;
 */"/>
    <method name="public QSyntaxHighlighter(com.trolltech.qt.gui.QTextDocument parent)" doc="/**
&lt;p&gt;Constructs a &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt; and installs it on &lt;tt&gt;parent&lt;/tt&gt;. The specified &lt;a href=&quot;QTextDocument.html&quot;&gt;&lt;tt&gt;QTextDocument&lt;/tt&gt;&lt;/a&gt; also becomes the owner of the &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt;.&lt;/p&gt;
 */"/>
    <method name="public QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit parent)" doc="/**
&lt;p&gt;Constructs a &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt; and installs it on &lt;tt&gt;parent&lt;/tt&gt; 's &lt;a href=&quot;QTextDocument.html&quot;&gt;&lt;tt&gt;QTextDocument&lt;/tt&gt;&lt;/a&gt;. The specified &lt;a href=&quot;QTextEdit.html&quot;&gt;&lt;tt&gt;QTextEdit&lt;/tt&gt;&lt;/a&gt; also becomes the owner of the &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt;.&lt;/p&gt;
 */"/>
    <method name="protected final int currentBlockState()" doc="/**
&lt;p&gt;Returns the state of the current text block. If no value is set, the returned value is -1.&lt;/p&gt;

@see &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockState(int)&quot;&gt;&lt;tt&gt;setCurrentBlockState&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="protected final com.trolltech.qt.gui.QTextBlockUserData currentBlockUserData()" doc="/**
&lt;p&gt;Returns the &lt;a href=&quot;QTextBlockUserData.html&quot;&gt;&lt;tt&gt;QTextBlockUserData&lt;/tt&gt;&lt;/a&gt; object previously attached to the current text block.&lt;/p&gt;

@see &lt;tt&gt;QTextBlock::userData&lt;/tt&gt;
@see &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockUserData(com.trolltech.qt.gui.QTextBlockUserData)&quot;&gt;&lt;tt&gt;setCurrentBlockUserData&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="public final com.trolltech.qt.gui.QTextDocument document()" doc="/**
&lt;p&gt;Returns the &lt;a href=&quot;QTextDocument.html&quot;&gt;&lt;tt&gt;QTextDocument&lt;/tt&gt;&lt;/a&gt; on which this syntax highlighter is installed.&lt;/p&gt;

@see &lt;a href=&quot;QSyntaxHighlighter.html#setDocument(com.trolltech.qt.gui.QTextDocument)&quot;&gt;&lt;tt&gt;setDocument&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="protected final com.trolltech.qt.gui.QTextCharFormat format(int pos)" doc="/**
&lt;p&gt;Returns the format at &lt;tt&gt;pos&lt;/tt&gt; inside the syntax highlighter's current text block.&lt;/p&gt;

@see &lt;a href=&quot;QSyntaxHighlighter.html#setFormat(int, int, com.trolltech.qt.gui.QColor)&quot;&gt;&lt;tt&gt;setFormat&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="protected final int previousBlockState()" doc="/**
&lt;p&gt;Returns the end state of the text block previous to the syntax highlighter's current block. If no value was previously set, the returned value is -1.&lt;/p&gt;

@see &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockState(int)&quot;&gt;&lt;tt&gt;setCurrentBlockState&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="public final void rehighlight()" doc="/**
&lt;p&gt;Redoes the highlighting of the whole document.&lt;/p&gt;
 */"/>
    <method name="protected final void setCurrentBlockState(int newState)" doc="/**
&lt;p&gt;Sets the state of the current text block to &lt;tt&gt;newState&lt;/tt&gt;.&lt;/p&gt;

@see &lt;a href=&quot;QSyntaxHighlighter.html#currentBlockState()&quot;&gt;&lt;tt&gt;currentBlockState&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="protected final void setCurrentBlockUserData(com.trolltech.qt.gui.QTextBlockUserData data)" doc="/**
&lt;p&gt;Attaches the given &lt;tt&gt;data&lt;/tt&gt; to the current text block. The ownership is passed to the underlying text document, i.e&amp;#x2e; the provided &lt;a href=&quot;QTextBlockUserData.html&quot;&gt;&lt;tt&gt;QTextBlockUserData&lt;/tt&gt;&lt;/a&gt; object will be deleted if the corresponding text block gets deleted.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;QTextBlockUserData.html&quot;&gt;&lt;tt&gt;QTextBlockUserData&lt;/tt&gt;&lt;/a&gt; can be used to store custom settings. In the case of syntax highlighting, it is in particular interesting as cache storage for information that you may figure out while parsing the paragraph's text.&lt;/p&gt;
&lt;p&gt;For example while parsing the text, you can keep track of parenthesis characters that you encounter ('{[(' and the like), and store their relative position and the actual QChar in a simple class derived from &lt;a href=&quot;QTextBlockUserData.html&quot;&gt;&lt;tt&gt;QTextBlockUserData&lt;/tt&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;    struct ParenthesisInfo
    {
        QChar char;
        int position;
    };

    struct BlockData : public QTextBlockUserData
    {
        QVector&amp;lt;ParenthesisInfo&amp;gt; parentheses;
    };&lt;/pre&gt;
&lt;p&gt;During cursor navigation in the associated editor, you can ask the current &lt;a href=&quot;QTextBlock.html&quot;&gt;&lt;tt&gt;QTextBlock&lt;/tt&gt;&lt;/a&gt; (retrieved using the QTextCursor::block() function) if it has a user data object set and cast it to your &lt;tt&gt;BlockData&lt;/tt&gt; object. Then you can check if the current cursor position matches with a previously recorded parenthesis position, and, depending on the type of parenthesis (opening or closing), find the next opening or closing parenthesis on the same level.&lt;/p&gt;
&lt;p&gt;In this way you can do a visual parenthesis matching and highlight from the current cursor position to the matching parenthesis. That makes it easier to spot a missing parenthesis in your code and to find where a corresponding opening/closing parenthesis is when editing parenthesis intensive code.&lt;/p&gt;

@see &lt;a href=&quot;QSyntaxHighlighter.html#currentBlockUserData()&quot;&gt;&lt;tt&gt;currentBlockUserData&lt;/tt&gt;&lt;/a&gt;
@see &lt;tt&gt;QTextBlock::setUserData&lt;/tt&gt; */"/>
    <method name="public final void setDocument(com.trolltech.qt.gui.QTextDocument doc)" doc="/**
&lt;p&gt;Installs the syntax highlighter on the given &lt;a href=&quot;QTextDocument.html&quot;&gt;&lt;tt&gt;QTextDocument&lt;/tt&gt;&lt;/a&gt; &lt;tt&gt;doc&lt;/tt&gt;. A &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt; can only be used with one document at a time.&lt;/p&gt;

@see &lt;a href=&quot;QSyntaxHighlighter.html#document()&quot;&gt;&lt;tt&gt;document&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="protected final void setFormat(int start, int count, com.trolltech.qt.gui.QTextCharFormat format)" doc="/**
&lt;p&gt;This function is applied to the syntax highlighter's current text block (i.e&amp;#x2e; the text that is passed to the &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt; function).&lt;/p&gt;
&lt;p&gt;The specified &lt;tt&gt;format&lt;/tt&gt; is applied to the text from the &lt;tt&gt;start&lt;/tt&gt; position for a length of &lt;tt&gt;count&lt;/tt&gt; characters (if &lt;tt&gt;count&lt;/tt&gt; is 0, nothing is done). The formatting properties set in &lt;tt&gt;format&lt;/tt&gt; are merged at display time with the formatting information stored directly in the document, for example as previously set with &lt;a href=&quot;QTextCursor.html&quot;&gt;&lt;tt&gt;QTextCursor&lt;/tt&gt;&lt;/a&gt;'s functions. Note that the document itself remains unmodified by the format set through this function.&lt;/p&gt;

@see &lt;a href=&quot;QSyntaxHighlighter.html#format(int)&quot;&gt;&lt;tt&gt;format&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="protected final void setFormat(int start, int count, com.trolltech.qt.gui.QFont font)" doc="/**
&lt;p&gt;The specified &lt;tt&gt;font&lt;/tt&gt; is applied to the current text block from the &lt;tt&gt;start&lt;/tt&gt; position for a length of &lt;tt&gt;count&lt;/tt&gt; characters.&lt;/p&gt;
&lt;p&gt;The other attributes of the current text block, e.g&amp;#x2e; the font and background color, are reset to default values.&lt;/p&gt;

@see &lt;a href=&quot;QSyntaxHighlighter.html#format(int)&quot;&gt;&lt;tt&gt;format&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="protected final void setFormat(int start, int count, com.trolltech.qt.gui.QColor color)" doc="/**
&lt;p&gt;The specified &lt;tt&gt;color&lt;/tt&gt; is applied to the current text block from the &lt;tt&gt;start&lt;/tt&gt; position for a length of &lt;tt&gt;count&lt;/tt&gt; characters.&lt;/p&gt;
&lt;p&gt;The other attributes of the current text block, e.g&amp;#x2e; the font and background color, are reset to default values.&lt;/p&gt;

@see &lt;a href=&quot;QSyntaxHighlighter.html#format(int)&quot;&gt;&lt;tt&gt;format&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="protected abstract void highlightBlock(java.lang.String text)" doc="/**
&lt;p&gt;Highlights the given text block. This function is called when necessary by the rich text engine, i.e&amp;#x2e; on text blocks which have changed.&lt;/p&gt;
&lt;p&gt;To provide your own syntax highlighting, you must subclass &lt;a href=&quot;QSyntaxHighlighter.html#QSyntaxHighlighter(com.trolltech.qt.gui.QTextEdit)&quot;&gt;&lt;tt&gt;QSyntaxHighlighter&lt;/tt&gt;&lt;/a&gt; and reimplement &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt;. In your reimplementation you should parse the block's &lt;tt&gt;text&lt;/tt&gt; and call &lt;a href=&quot;QSyntaxHighlighter.html#setFormat(int, int, com.trolltech.qt.gui.QColor)&quot;&gt;&lt;tt&gt;setFormat&lt;/tt&gt;&lt;/a&gt; as often as necessary to apply any font and color changes that you require. For example:&lt;/p&gt;
&lt;pre&gt;    void MyHighlighter::highlightBlock(const QString &amp;amp;text)
    {
        QTextCharFormat myClassFormat;
        myClassFormat.setFontWeight(QFont::Bold);
        myClassFormat.setForeground(Qt::darkMagenta);
        QString pattern = &amp;quot;\\bMy[A-Za-z]+\\b&amp;quot;;

        QRegExp expression(pattern);
        int index = text.indexOf(expression);
        while (index &amp;gt;= 0) {
            int length = expression.matchedLength();
            setFormat(index, length, myClassFormat);
            index = text.indexOf(expression, index + length);
         }
     }&lt;/pre&gt;
&lt;p&gt;Some syntaxes can have constructs that span several text blocks. For example, a C++ syntax highlighter should be able to cope with &lt;tt&gt;/&lt;/tt&gt;&lt;tt&gt;*...*&lt;/tt&gt;&lt;tt&gt;/&lt;/tt&gt; multiline comments. To deal with these cases it is necessary to know the end state of the previous text block (e.g&amp;#x2e; &amp;quot;in comment&amp;quot;).&lt;/p&gt;
&lt;p&gt;Inside your &lt;a href=&quot;QSyntaxHighlighter.html#highlightBlock(java.lang.String)&quot;&gt;&lt;tt&gt;highlightBlock&lt;/tt&gt;&lt;/a&gt; implementation you can query the end state of the previous text block using the &lt;a href=&quot;QSyntaxHighlighter.html#previousBlockState()&quot;&gt;&lt;tt&gt;previousBlockState&lt;/tt&gt;&lt;/a&gt; function. After parsing the block you can save the last state using &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockState(int)&quot;&gt;&lt;tt&gt;setCurrentBlockState&lt;/tt&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;QSyntaxHighlighter.html#currentBlockState()&quot;&gt;&lt;tt&gt;currentBlockState&lt;/tt&gt;&lt;/a&gt; and &lt;a href=&quot;QSyntaxHighlighter.html#previousBlockState()&quot;&gt;&lt;tt&gt;previousBlockState&lt;/tt&gt;&lt;/a&gt; functions return an int value. If no state is set, the returned value is -1. You can designate any other value to identify any given state using the &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockState(int)&quot;&gt;&lt;tt&gt;setCurrentBlockState&lt;/tt&gt;&lt;/a&gt; function. Once the state is set the &lt;a href=&quot;QTextBlock.html&quot;&gt;&lt;tt&gt;QTextBlock&lt;/tt&gt;&lt;/a&gt; keeps that value until it is set set again or until the corresponding paragraph of text gets deleted.&lt;/p&gt;
&lt;p&gt;For example, if you're writing a simple C++ syntax highlighter, you might designate 1 to signify &amp;quot;in comment&amp;quot;. For a text block that ended in the middle of a comment you'd set 1 using &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockState(int)&quot;&gt;&lt;tt&gt;setCurrentBlockState&lt;/tt&gt;&lt;/a&gt;, and for other paragraphs you'd set 0. In your parsing code if the return value of &lt;a href=&quot;QSyntaxHighlighter.html#previousBlockState()&quot;&gt;&lt;tt&gt;previousBlockState&lt;/tt&gt;&lt;/a&gt; is 1, you would highlight the text as a C++ comment until you reached the closing &lt;tt&gt;*&lt;/tt&gt;&lt;tt&gt;/&lt;/tt&gt;.&lt;/p&gt;

@see &lt;a href=&quot;QSyntaxHighlighter.html#previousBlockState()&quot;&gt;&lt;tt&gt;previousBlockState&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSyntaxHighlighter.html#setFormat(int, int, com.trolltech.qt.gui.QColor)&quot;&gt;&lt;tt&gt;setFormat&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSyntaxHighlighter.html#setCurrentBlockState(int)&quot;&gt;&lt;tt&gt;setCurrentBlockState&lt;/tt&gt;&lt;/a&gt; */"/>
</class>
