Description
I created a TextArea component in QML, and similar to this example, I created a DocumentHandler class based on a pointer to a QQuickTextDocument, which is taken through the textDocument property. I need this in order to be able to format the text, that is, make it bold, underlined, italic, strikeOut etc.
What I need
I need to get a text where the formatted parts will be presented as HTML tags.
e.g. Bold text ultimately I would like to get in the form <b>Bold text</b>. Or for example Bold and italic text I would like to get in the form <b><i>Bold and italic text</i></b> (the order in which the tags are placed does not matter).
What I tried
I tried to use the toHtml() function, but this function does not suit me because:
- It generates a lot of unnecessary information that I don't need. For example for Bold text it returned the following result:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Roboto'; font-size:14px; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Bold text</span></p></body></html>
- The usual tags that I need to represent the text (
<b>,<i>etc.), this function is formed in the form of thestyleattribute of the<span>tag. So it changes the bold with this line:<span style=" font-weight:600;">.