如何在 Qt 中使用 QSyntaxHighlighter 类在 QML TextEdit 上实现富文本逻辑? [英] How to implement rich text logic on QML TextEdit with QSyntaxHighlighter class in Qt?

查看:16
本文介绍了如何在 Qt 中使用 QSyntaxHighlighter 类在 QML TextEdit 上实现富文本逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 QML 文件中有一个 TextEdit,我有一个 QSyntaxHighlighter C++ 类.我想在 C++ 类中指定突出显示逻辑并将其应用于 TextEdit,但我不确定如何在 QML 对象和 C++ 类之间建立连接.您还可以提供一些示例代码吗?我找不到如何使用 Qt 文档来实现它.

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.

推荐答案

你可以使用TextEdit::textDocument,它包含 QQuickTextDocument,获取对底层 QTextDocument 的访问权限,您可以将其传递给 QSyntaxHighlighter 构造函数.

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

这篇关于如何在 Qt 中使用 QSyntaxHighlighter 类在 QML TextEdit 上实现富文本逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆