I try to draw a text on a QImage using the QTextDocument. How to set a default ("body") style?
Currently I use a <p>
tag, like this
QPainter painter(_image);
QTextDocument doc;
doc.setDefaultStyleSheet("p { color : green; background-color : black; }");
doc.setHtml("<p>test 123</p>");
doc.drawContents(&painter,_image->rect());
I would like to get rid of <p>
tag
doc.setHtml("test 123");
I have tried
doc.setDefaultStyleSheet("body { color : green; background-color : black; }");
doc.setDefaultStyleSheet("{ color : green; background-color : black; }");
doc.setDefaultStyleSheet("color : green; background-color : black; ");
doc.setDefaultStyleSheet("QImage { color : green; background-color : black; }");
EDIT:
I have also tried
doc.setDefaultStyleSheet("* { color : green; background-color : black; }");
You should wrap content with <body>
tag:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTextDocument doc;
doc.setDefaultStyleSheet("body { color : green; background-color : black; }");
doc.setHtml("<body>test 123</body>");
QTextEdit textEdit;
textEdit.setDocument(&doc);
textEdit.show();
return app.exec();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With