Reputation: 1480
Qt 5.14 has introduced setting markdown directly in QTextDocument. My question is how I can style the rendered richtext e.g. the heading color?
The QTextDocument::seDefaultStyleSheet
only works for html content. For non-html rich text, is there a way to modify the default QTextDocument formatting directly or do I need iterate over all blocks and set the formatting for each block manually?
Upvotes: 5
Views: 753
Reputation: 335
I ran into the same issue, my workaround is:
document->setDefaultStyleSheet("h1 { color: red; }");
document->setMarkdown("# Hello World");
document->setHtml(document->toHtml()); // get markdown as HTML and set it as HTML, now the CSS is applied
It's not ideal, but it works :)
Upvotes: 4