qtextedit 默认文案_c-Qt库中控件的默认HTML样式

QLabel无法完成您想要的事情. QLabel旨在容纳基本文本标签-它的HTML支持相当…绳索.

但是,您可以使用QTextEdit&另外,QTextDocument.

尝试这样的事情(我是从内存中写出来的,因此它可能无法编译或100%正确):

QTextDocument *doc = new QTextDocument(this);

doc->setDefaultStyleSheet("h3 { font-color: red; }");

QTextEdit *edit = new QTextEdit(this);

edit->setDocument(doc);

edit->setHTML("this is a red

heading

");

重要的是使用QTextDocument,它允许您更改HTML样式表.从QT文档中:

The default style sheet is applied to all newly HTML formatted text that is inserted into the document, for example using setHtml() or QTextCursor::insertHtml().

The style sheet needs to be compliant to CSS 2.1 syntax.

Note: Changing the default style sheet does not have any effect to the existing content of the document.

编辑:

要获取默认样式表,可以调用QTextDocument :: DefaultStyleSheet()-但是,这仅适用于QTextDocuments,并且可能适用于或可能不适用于所有Qt控件(包括QLabel).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值