1QSyntaxHighlighter(3qt)                                QSyntaxHighlighter(3qt)
2
3
4

NAME

6       QSyntaxHighlighter - Base class for implementing QTextEdit syntax
7       highlighters
8

SYNOPSIS

10       #include <qsyntaxhighlighter.h>
11
12       Inherits Qt.
13
14   Public Members
15       QSyntaxHighlighter ( QTextEdit * textEdit )
16       virtual ~QSyntaxHighlighter ()
17       virtual int highlightParagraph ( const QString & text, int
18           endStateOfLastPara ) = 0
19       void setFormat ( int start, int count, const QFont & font, const QColor
20           & color )
21       void setFormat ( int start, int count, const QColor & color )
22       void setFormat ( int start, int count, const QFont & font )
23       QTextEdit * textEdit () const
24       void rehighlight ()
25       int currentParagraph () const
26

DESCRIPTION

28       The QSyntaxHighlighter class is a base class for implementing QTextEdit
29       syntax highlighters.
30
31       A syntax highligher automatically highlights parts of the text in a
32       QTextEdit. Syntax highlighters are often used when the user is entering
33       text in a specific format (for example, source code) and help the user
34       to read the text and identify syntax errors.
35
36       To provide your own syntax highlighting for QTextEdit, you must
37       subclass QSyntaxHighlighter and reimplement highlightParagraph().
38
39       When you create an instance of your QSyntaxHighlighter subclass, pass
40       it the QTextEdit that you want the syntax highlighting to be applied
41       to. After this your highlightParagraph() function will be called
42       automatically whenever necessary. Use your highlightParagraph()
43       function to apply formatting (e.g. setting the font and color) to the
44       text that is passed to it.
45
46       See also Basic Widgets and Text Related Classes.
47

MEMBER FUNCTION DOCUMENTATION

QSyntaxHighlighter::QSyntaxHighlighter ( QTextEdit * textEdit )

50       Constructs the QSyntaxHighlighter and installs it on textEdit.
51
52       It is the caller's responsibility to delete the QSyntaxHighlighter when
53       it is no longer needed.
54

QSyntaxHighlighter::~QSyntaxHighlighter () [virtual]

56       Destructor. Uninstalls this syntax highlighter from the textEdit()
57

int QSyntaxHighlighter::currentParagraph () const

59       Returns the id of the paragraph which is highlighted, or -1 of no
60       paragraph is currently highlighted.
61
62       Usually this function is called from within highlightParagraph().
63

int QSyntaxHighlighter::highlightParagraph ( const QString & text, int

65       endStateOfLastPara ) [pure virtual]
66       This function is called when necessary by the rich text engine, i.e. on
67       paragraphs which have changed.
68
69       In your reimplementation you should parse the paragraph's text and call
70       setFormat() as often as necessary to apply any font and color changes
71       that you require. Your function must return a value which indicates the
72       paragraph's end state: see below.
73
74       Some syntaxes can have constructs that span paragraphs. For example, a
75       C++ syntax highlighter should be able to cope with /*...*/ comments
76       that span paragraphs. To deal with these cases it is necessary to know
77       the end state of the previous paragraph (e.g. "in comment").
78
79       If your syntax does not have paragraph spanning constructs, simply
80       ignore the endStateOfLastPara parameter and always return 0.
81
82       Whenever highlightParagraph() is called it is passed a value for
83       endStateOfLastPara. For the very first paragraph this value is always
84       -2. For any other paragraph the value is the value returned by the most
85       recent highlightParagraph() call that applied to the preceding
86       paragraph.
87
88       The value you return is up to you. We recommend only returning 0 (to
89       signify that this paragraph's syntax highlighting does not affect the
90       following paragraph), or a positive integer (to signify that this
91       paragraph has ended in the middle of a paragraph spanning construct).
92
93       To find out which paragraph is highlighted, call currentParagraph().
94
95       For example, if you're writing a simple C++ syntax highlighter, you
96       might designate 1 to signify "in comment". For a paragraph that ended
97       in the middle of a comment you'd return 1, and for other paragraphs
98       you'd return 0. In your parsing code if endStateOfLastPara was 1, you
99       would highlight the text as a C++ comment until you reached the closing
100       */.
101

void QSyntaxHighlighter::rehighlight ()

103       Redoes the highlighting of the whole document.
104

void QSyntaxHighlighter::setFormat ( int start, int count, const QFont & font,

106       const QColor & color )
107       This function is applied to the syntax highlighter's current paragraph
108       (the text of which is passed to the highlightParagraph() function).
109
110       The specified font and color are applied to the text from position
111       start for count characters. (If count is 0, nothing is done.)
112

void QSyntaxHighlighter::setFormat ( int start, int count, const QColor &

114       color )
115       This is an overloaded member function, provided for convenience. It
116       behaves essentially like the above function.
117

void QSyntaxHighlighter::setFormat ( int start, int count, const QFont & font

119       )
120       This is an overloaded member function, provided for convenience. It
121       behaves essentially like the above function.
122

QTextEdit * QSyntaxHighlighter::textEdit () const

124       Returns the QTextEdit on which this syntax highlighter is installed
125
126

SEE ALSO

128       http://doc.trolltech.com/qsyntaxhighlighter.html
129       http://www.trolltech.com/faq/tech.html
130
132       Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
133       license file included in the distribution for a complete license
134       statement.
135

AUTHOR

137       Generated automatically from the source code.
138

BUGS

140       If you find a bug in Qt, please report it as described in
141       http://doc.trolltech.com/bughowto.html.  Good bug reports help us to
142       help you. Thank you.
143
144       The definitive Qt documentation is provided in HTML format; it is
145       located at $QTDIR/doc/html and can be read using Qt Assistant or with a
146       web browser. This man page is provided as a convenience for those users
147       who prefer man pages, although this format is not officially supported
148       by Trolltech.
149
150       If you find errors in this manual page, please report them to qt-
151       bugs@trolltech.com.  Please include the name of the manual page
152       (qsyntaxhighlighter.3qt) and the Qt version (3.3.8).
153
154
155
156Trolltech AS                    2 February 2007        QSyntaxHighlighter(3qt)
Impressum