Qt ignores CSS in QTextDocument

寵の児 提交于 2020-01-11 09:51:39

问题


Here is a small snippet of my code, I don't know why but Qt is ignoring the css.

QTextDocument *mTextDocument = new QTextDocument(0);
QTextEdit *textEdit = new QTextEdit(0);
mTextDocument->setDefaultStyleSheet(QString::fromUtf8("body{background-color: rgb(0,111,200);}"));
QTextCursor *_cursor = new QTextCursor(mTextDocument);
textEdit->setDocument(mTextDocument);
_cursor->insertBlock();
_cursor->insertHtml("<html><body><p>Hello world</p></body></html>");
textEdit->show();

I'm using Qt 4.8.


回答1:


Your document already has html and body tags, so they are simply ignored when they are found in insertHtml.

If you were using QTextEdit::setHtml, they would be new elements and the default stylesheet would be applied to them.



来源:https://stackoverflow.com/questions/15730224/qt-ignores-css-in-qtextdocument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!