[英]HTML inserted into QTextEdit does not conform to style sheet
我有一個停靠的QTextEdit,它用於在QT c ++ gui中模擬調試終端,並將其設置為帶有白色文本的黑色背景。
我正在嘗試使用它來打印來自QXmlSchemaValidator
錯誤消息,但是來自模式驗證器的消息是html格式的,並且每當我將它們插入QTextEdit
,它都會恢復為默認字體,並且最終出現黑色文本黑色的背景。
實際的消息是這樣的:
<html xmlns='http://www.w3.org/1999/xhtml/'>
<body>
<p>Content of element
<span class='XQuery-keyword'>minValue</span> does not match its type definition: <span class='XQuery-data'>fu</span> is not valid according to <span class='XQuery-type'>xs:decimal</span>..
</p>
</body>
</html>
使用setAcceptRichText(false)
不能解決問題,如果我使用insertPlainText()
將文本添加到lineEdit
,它將刪除所有換行符,並將html標記lineEdit
在錯誤消息中,這是不可接受的。
有什么方法可以顯示HTML RTF文本,但又不會丟失樣式表字體?
我在計算機上進行了測試。 它運作完美。 用這個:
edit->setHtml(htmlDescription);
edit->selectAll();
edit->setTextColor(Qt::green);
//Ok, but clear selection
QTextCursor cur = edit->textCursor();
cur.clearSelection();
edit->setTextCursor(cur);
這有點麻煩,但是我要解決的方法是在將模式驗證器消息中的HTML標記添加到文本編輯之前,將其刪除。
QString errorMsg = msg.statusMessage().remove(QRegExp("<[^>]*>"));
textEdit->setText(errorMsg);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.