Qt5 Syntax Highlighting in QML

后端 未结 5 1607
谎友^
谎友^ 2021-02-05 10:38

I am working on a QtQuick 2.0 presentation and I would like to embed some code samples. is it possible easily to create a syntax highlighting qml element.

C

5条回答
  •  無奈伤痛
    2021-02-05 11:19

    There is no obvious way to achieve syntax highlighting in QML.

    One could implement one's own declarative item, performing the actual highlighting with QSyntaxHighlighter but then one would have to define its own highlighting rules for language of the source code in question. I would't do that amount of coding for a presentation.

    Instead I would display the code in a WebView item with the highlighting already applied as static HTML markup or with the help of a JavaScript highlighting library, for expample highlight.js.

    Update 1

    If the WebView item is indeed unusable, even the simple Text item with its rudimentary HTML support should be enough to handle the source code highlighting usecase if fed with static HTML.

提交回复
热议问题