KSyntaxHighlighting
- Basic Highlighting
- Advanced Use
- Further References
Basic Highlighting
If all you need is doing syntax highlighting for a fixed language and using a color theme matching the current system palette this is a matter of adding the SyntaxHighlighter
component from the org.kde.syntaxhighlighting
QML module to a text control.
Advanced Use
For more complex uses the syntax definition might not be fixed but depend on input data (e.g. derived from its mimetype or file name), or a user selection. In the C++ API this is enabled by the Repository
class, which is now also available in QML as a singleton object.
The following example shows how to use this for a simple syntax selection combo box.
Handling color themes is also possible, similarly to syntax definitions. Themes can be listed, their properties can be accessed and they can be set by theme object or name on the highlighter. Like in the C++ API it's also possible to just ask for the light or dark default theme.
Further References
There's a more complete and pure-QML example in examples/qml/example.qml
provided as part of the KSyntaxHighlighting source code that can be run with qmlscene
.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.