PDA

View Full Version : QTextEdit: About letting Qt stop modifying HTML text



Amr
2nd April 2015, 12:52
Hi all,

Suppose that you have the following code fragment:


QTextEdit textEdit;

textEdit.setHtml("<h2>Description</h2>\n<p>More Details Here</p>");
textEdit.show();
std::cout << "textEdit.toHtml() = " << textEdit.toHtml().toStdString() << std::endl << std::endl;


The output is displayed as expected. But the HTML format is as follows (from std::cout):

<!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:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
<p style=" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:x-large; font-weight:600;">Description</span></p>
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">More Details here.</p></body></html>

My question is: Is there anyway for keeping the original HTML tags? When I tried to remove the first line (<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">) using designer or by code, I still get the HTML format that qt forces to be. I know that the displayed rendered text is correct. But my concern is to keep original HTML text untouched (for another application that takes that text from Qt application and the former crashes due to different standard text coming from Qt).

Many thanks in advance.

anda_skoa
2nd April 2015, 13:12
QTextEdit, or rather its internal QTextDocument, parses the given HTML and creates a document structure for rendering it.
Like browsers do when they create their DOM tree.

When you export to HTML each engine will take its current internal representation and create the closest HTML for that.

If you want to keep the original HTML, keep the original HTML :)

Cheers,
_