How to read syntax highlighting data from QTextDocument?
-
My simple test program
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QPlainTextEdit *edit = new QPlainTextEdit(this); KSyntaxHighlighting::SyntaxHighlighter *highlighter; auto doc = edit->document(); highlighter = new KSyntaxHighlighting::SyntaxHighlighter(doc); const auto def = repository.definitionForName("C++"); highlighter->setDefinition(def); const auto theme = repository.theme("Breeze Light"); highlighter->setTheme(theme); highlighter->rehighlight(); edit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); setCentralWidget(edit); }
Now I want get information about current syntax type of clicked point or caret position.
For example, if I click on "class" , I get information "keyword", if I click inside string, get information "string". Is such information available with KF5 Syntax Highlighting or only further - color of theme? -
Hi,
Do you mean you would like the behaviour of a code editor ?
-
That does not answer my question.
QSyntaxHighlighter is a class used to highlight text following some rules, it has no additional knowledge about what it highlights.