看看这一小段Qt代码
qDebug() << "CONTENT" << content;
QTextEdit *te = new QTextEdit(this);
te->setHtml(content);
qDebug() << "CONTENT AFTER " << te->toHtml();
内容最初包含此HTML
<!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:'Calibri'; font-size:10pt; font-weight:400; font-style:normal;\">
<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">
<span style=\" font-family:'Verdana'; color:#0b333c;\">MY TEXT</span>
</p>
</body>
</html>"
...但te->toHtml()
的输出是......
<!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\">\np, li { white-space: pre-wrap; }\n</style>
</head>
<body style=\" font-family:'Calibri'; font-size:10pt; 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;\"> </p>
<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">
<span style=\" font-family:'Verdana'; color:#0b333c;\">MY TEXT</span>
</p>
</body>
</html>
正如您所看到的,QTextEdit
无缘无故地在段落之前。这非常烦人,我绝对需要避免它。
有什么想法吗?我真的无法弄清楚如何摆脱这种行为。这可能是个错误吗?