📄 qsyntaxhighlighter.3qt
字号:
'\" t.TH QSyntaxHighlighter 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQSyntaxHighlighter \- Base class for implementing QTextEdit syntax highlighters.SH SYNOPSIS\fC#include <qsyntaxhighlighter.h>\fR.PPInherits Qt..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQSyntaxHighlighter\fR ( QTextEdit * textEdit )".br.ti -1c.BI "virtual \fB~QSyntaxHighlighter\fR ()".br.ti -1c.BI "virtual int \fBhighlightParagraph\fR ( const QString & text, int endStateOfLastPara ) = 0".br.ti -1c.BI "void \fBsetFormat\fR ( int start, int count, const QFont & font, const QColor & color )".br.ti -1c.BI "void \fBsetFormat\fR ( int start, int count, const QColor & color )".br.ti -1c.BI "void \fBsetFormat\fR ( int start, int count, const QFont & font )".br.ti -1c.BI "QTextEdit * \fBtextEdit\fR () const".br.ti -1c.BI "void \fBrehighlight\fR ()".br.in -1c.SH DESCRIPTIONThe QSyntaxHighlighter class is a base class for implementing QTextEdit syntax highlighters..PPA syntax highligher automatically highlights parts of the text in a QTextEdit. 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..PPTo provide your own syntax highlighting for QTextEdit, you must subclass QSyntaxHighlighter and reimplement highlightParagraph()..PPWhen you create an instance of your QSyntaxHighlighter subclass, pass it the QTextEdit that you want the syntax highlighting to be applied to. After this your highlightParagraph() function will be called automatically whenever necessary. Use your highlightParagraph() function to apply formatting (e.g. setting the font and color) to the text that is passed to it..PPSee also Basic Widgets and Text Related Classes..SH MEMBER FUNCTION DOCUMENTATION.SH "QSyntaxHighlighter::QSyntaxHighlighter ( QTextEdit * textEdit )"Constructs the QSyntaxHighlighter and installs it on \fItextEdit\fR. Ownership of the QSyntaxHighlighter is transferred to the \fItextEdit\fR.SH "QSyntaxHighlighter::~QSyntaxHighlighter ()\fC [virtual]\fR"Destructor. Uninstalls this syntax highlighter from the textEdit().SH "int QSyntaxHighlighter::highlightParagraph ( const QString & text, int endStateOfLastPara )\fC [pure virtual]\fR"This function is called when necessary by the rich text engine, i.e. on paragraphs which have changed..PPIn your reimplementation you should parse the paragraph's \fItext\fR and call setFormat() as often as necessary to apply any font and color changes that you require. Your function must return a value which indicates the paragraph's end state: see below..PPSome syntaxes can have constructs that span paragraphs. For example, a C++ syntax highlighter should be able to cope with \fC/\fR\fC*...*\fR\fC/\fR comments that span paragraphs. To deal with these cases it is necessary to know the end state of the previous paragraph (e.g. "in comment")..PPIf your syntax does not have paragraph spanning constructs, simply ignore the \fIendStateOfLastPara\fR parameter and always return 0..PPWhenever highlightParagraph() is called it is passed a value for \fIendStateOfLastPara\fR. For the very first paragraph this value is always -2. For any other paragraph the value is the value returned by the most recent highlightParagraph() call that applied to the preceding paragraph..PPThe value you return is up to you. We recommend only returning 0 (to signify that this paragraph's syntax highlighting does not affect the following paragraph), or a positive integer (to signify that this paragraph has ended in the middle of a paragraph spanning construct)..PPFor example, if you're writing a simple C++ syntax highlighter, you might designate 1 to signify "in comment". For a paragraph that ended in the middle of a comment you'd return 1, and for other paragraphs you'd return 0. In your parsing code if \fIendStateOfLastPara\fR was 1, you would highlight the text as a C++ comment until you reached the closing \fC*\fR\fC/\fR..SH "void QSyntaxHighlighter::rehighlight ()"Redoes the highlighting of the whole document..SH "void QSyntaxHighlighter::setFormat ( int start, int count, const QFont & font, const QColor & color )"This function is applied to the syntax highlighter's current paragraph (the text of which is passed to the highlightParagraph() function)..PPThe specified \fIfont\fR and \fIcolor\fR are applied to the text from position \fIstart\fR for \fIcount\fR characters. (If \fIcount\fR is 0, nothing is done.).SH "void QSyntaxHighlighter::setFormat ( int start, int count, const QColor & color )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..SH "void QSyntaxHighlighter::setFormat ( int start, int count, const QFont & font )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..SH "QTextEdit * QSyntaxHighlighter::textEdit () const"Returns the QTextEdit on which this syntax highlighter isinstalled.SH "SEE ALSO".BR http://doc.trolltech.com/qsyntaxhighlighter.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qsyntaxhighlighter.3qt) and the Qtversion (3.1.1).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -