当前位置: 首页 > 工具软件 > Thinkin' Tags > 使用案例 >

qstring 颜色 html,qt - Get plain text from QString with HTML tags - Stack Overflow

阎宝
2023-12-01

The question is a bit dusty now, but for anyone checking, it is (has become?) possible to use QTextDocumentFragment to convert HTML to plaintext in the Qt way.

This approach may offer consistency dependending on your purpose, as well as robustness (of course depending on the Qt folks time :) - but their user base is sizable, and so far it has worked perfectly for me).

I tried something like the below out in Python, I think the mechanics should be about the same in C++ too.

from PySide2.QtGui import QTextDocumentFragment

plain = QTextDocumentFragment.fromHtml(

"

someHtml it was so booold!"

).toPlainText()

(Additionally, the Qt documentation suggests that you can just pass in the QString to fromHtml there.)

 类似资料: