QSyntaxHighlighter(3qt)
π QSyntaxHighlighter β the QSyntaxHighlighter(3qt) glow-up π
okay bestie, sit DOWN, because we're about to talk about the base class for implementing QTextEdit syntax highlighters and honestly? she's iconic. π
β¨ NAME β¨
QSyntaxHighlighter β the base class for implementing QTextEdit syntax highlighters. that's her. that's the whole vibe. π
πΈ SYNOPSIS πΈ
#include <qsyntaxhighlighter.h>
Inherits Qt.
π¦ Public Members π¦
QSyntaxHighlighter ( QTextEdit * textEdit )
virtual ~QSyntaxHighlighter ()
virtual int highlightParagraph ( const QString & text, int
endStateOfLastPara ) = 0
void setFormat ( int start, int count, const QFont & font, const QColor
& color )
void setFormat ( int start, int count, const QColor & color )
void setFormat ( int start, int count, const QFont & font )
QTextEdit * textEdit () const
void rehighlight ()
int currentParagraph () const
π DESCRIPTION π
The QSyntaxHighlighter class is a base class for implementing QTextEdit syntax highlighters. she's the blueprint, the template, the mother. π
A 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. basically she's the reason your code looks pretty instead of like a sad grey wall of text. π
To provide your own syntax highlighting for QTextEdit, you must subclass QSyntaxHighlighter and reimplement highlightParagraph(). no shortcuts bestie, you gotta do the work. π«Ά
When 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. she just shows up when she's needed, no invitation required, main character energy fr fr. β¨
See also Basic Widgets and Text Related Classes.
π MEMBER FUNCTION DOCUMENTATION π
π QSyntaxHighlighter::QSyntaxHighlighter ( QTextEdit * textEdit )
Constructs the QSyntaxHighlighter and installs it on textEdit. she has arrived and she is seated. π
It is the caller's responsibility to delete the QSyntaxHighlighter when it is no longer needed. yes bestie, YOU clean up after yourself, nobody else is gonna do it for you. π
π¦ QSyntaxHighlighter::~QSyntaxHighlighter () [virtual]
Destructor. Uninstalls this syntax highlighter from the textEdit(). she's leaving the group chat, gracefully. π
β int QSyntaxHighlighter::currentParagraph () const
Returns the id of the paragraph which is highlighted, or -1 of no paragraph is currently highlighted. (yes that's literally what it says, no cap, -1 means "nobody's home".) π
Usually this function is called from within highlightParagraph().
π§ int QSyntaxHighlighter::highlightParagraph ( const QString & text, int endStateOfLastPara ) [pure virtual]
This function is called when necessary by the rich text engine, i.e. on paragraphs which have changed. she only wakes up when something actually changed, we love an efficient queen. β
In your reimplementation you should parse the paragraph's text 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. π
Some syntaxes can have constructs that span paragraphs. For example, a C++ syntax highlighter should be able to cope with /*...*/ 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"). yes bestie, she has memory, she's tracking the lore. π§
If your syntax does not have paragraph spanning constructs, simply ignore the endStateOfLastPara parameter and always return 0.
Whenever highlightParagraph() is called it is passed a value for endStateOfLastPara. 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.
The 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).
To find out which paragraph is highlighted, call currentParagraph().
For 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 endStateOfLastPara was 1, you would highlight the text as a C++ comment until you reached the closing */. see? the lore carries over paragraph to paragraph. she remembers. always. π
πΈ void QSyntaxHighlighter::rehighlight ()
Redoes the highlighting of the whole document. full glow-up from scratch, no patches, no half measures. β¨
π 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).
The specified font and color are applied to the text from position start for count characters. (If count is 0, nothing is done.) zero means nothing happens, do not pass go, do not collect $200. π«
π 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. same energy, less arguments, we love a shortcut. π
π 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. yep, another one, she's flexible like that. π
π QTextEdit * QSyntaxHighlighter::textEdit () const
Returns the QTextEdit on which this syntax highlighter is installed. that's her home. that's where she lives. π
π« SEE ALSO π«
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
π¦ AUTHOR π¦
Generated automatically from the source code. (no human hand-wrote this one, she was born from the machine itself, lowkey iconic.) π€β¨
π BUGS π
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. (bestie, a good bug report is a love letter. be specific. be kind. π«Ά)
The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.
If you find errors in this manual page, please report them toqt-bugs@trolltech.com. Please include the name of the manual page (qsyntaxhighlighter.3qt) and the Qt version (3.3.8). don't forget the receipts bestie, they need the deets. π
okay that's the whole thing, you ate that. π this little beauty came to you courtesy of Trolltech AS, dated 2 February 2007, and she's repping Qt version 3.3.8 β and yes, that's the manual page qsyntaxhighlighter.3qt, so if you ever need to cite her, you know exactly who she is. periodt. πβ¨π
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms