Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement rich text logic on QML TextEdit with QSyntaxHighlighter class in Qt?

Tags:

c++

qt

qml

qtquick2

I have a TextEdit in my QML file and I have a QSyntaxHighlighter C++ class. I want to specify the highlighting logic in the C++ class and apply it to the TextEdit, but I am not sure how to make the connection between the QML object and the C++ class. Can you also please provide some sample code? I couldn't find how to implement it with the Qt documentation.

like image 408
Francisco Hernandez Avatar asked Dec 24 '22 02:12

Francisco Hernandez


1 Answers

You can use TextEdit::textDocument, which holds an instance of QQuickTextDocument, to gain access to the underlying QTextDocument that you can pass to QSyntaxHighlighter constructor.

like image 122
jpnurmi Avatar answered Dec 28 '22 07:12

jpnurmi