qlabel编辑文本时html编辑,如何在QLabel中设置文本并显示“<>”字符?

使用PySide2(基本上是PyQt5),我试图在一个QLabel中setText,该QLabel的字符串中包含字符'&lt;'和'&gt;'。但是,由于这些字符用于修改字体,因此这两个字符中的任何内容都将消失。我试着用反斜杠来逃避,但似乎还是没用。。。在

如何在QLabel中显示“&lt;”和“&gt;”字符?在

编辑:下面是我的代码在做什么(只是抓住了重要的部分):# color and text get set at various places in my code (len_infs is just the length of the

# influence item list - hopefully that's obvious...)

#

color = '#FF0000'

text = 'Influence count &lt%d&gt exceeds minimum row count...' %len_infs

# status_label is a QLabel that displays the text in the appropriate color within the label

#

status_label.setText('status: %s' %(color, text))

如您所见,我根据Ekhurvo的建议在字符串中使用了&lt和&gt,但在生成的QLabel文本中没有得到'&lt;'或'&gt;'

我要它打印status: Influence count <7> exceeds minimum row count...

但它实际上打印status: Influence count &lt7&gt exceeds minimum row count...

在这两种情况下,“status:”都是白色的,而其余的则是预期的红色。在

注意:在字符串中使用''会导致status: Influence count exceeds minimum row count...

我还需要做什么才能正确格式化字符串?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值