QTextDocument:获取特定格式的单词

问题描述

我有一个带有一些文本的 QTextDocument,其中部分文本带有下划线(拼写错误)。 我想解析文本并获取带有位置的格式化单词。 怎么样?

for( auto textBlock = document()->begin(); textBlock != document()->end(); textBlock = textBlock.next() )
        {
            qDebug() << "textBlock::text: " << textBlock.text();
            for (auto t = textBlock.begin(); t != textBlock.end(); ++t)
            {
                qDebug() << "";
                auto fragment = t.fragment();
                qDebug() << fragment.text();
                auto format = fragment.charFormat();
                qDebug() << format.fontUnderline();
                qDebug() << format.underlineStyle();
                qDebug() << format.underlineColor();
                qDebug() << "";
            }
        }

但这总是输出:

  1. QTextDocument 的全部内容。
  2. 没有下划线,没有样式...

所以显然我需要换一种方式来理解它,或者以某种方式变得更深入?怎么样?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...