Apply stylesheet to HTML content in QTextEdit
Asked Answered
S

2

7

I have a QTextEdit where I do display some HTML. Could I apply a stylesheet to that very HTML content?

Do not confuse it with applying a Qt stylesheet to the QTextEdit (that I know). I want to change the appearance of what is in the QTextEdit widget ("HTML").

Related: Default HTML style for controls in the Qt library

Sunday answered 10/3, 2015 at 23:1 Comment(1)
Also #932592 is interestingSunday
C
4

You can have a look at Qt ignores CSS in QTextDocument which uses QTextDocument and the defaultStyleSheet property / setDefaultStyleSheet() http://doc.qt.io/qt-5/qtextdocument.html#defaultStyleSheet-prop

Note that QTextEdit only supports the following html subset http://doc.qt.io/qt-5/richtext-html-subset.html if you want to do more then that you are probably best of using the QWebkit or QWebEngine modules depending on which Qt version your targeting.

Carolinecarolingian answered 11/3, 2015 at 1:4 Comment(0)
T
2

As per Qt5, many CSS properties are supported:

The following table lists the CSS properties supported by Qt's rich text engine.

The best way to apply them is to start your document with <style> and use classes. However the <node style=""> attribute also works.

Twophase answered 29/8, 2017 at 18:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.