Qt ignores CSS in QTextDocument
Asked Answered
O

1

3

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.

Olivaolivaceous answered 31/3, 2013 at 14:6 Comment(0)
J
2

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.

Januarius answered 31/3, 2013 at 19:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.