Python - pyqt5 - 将文本设置为具有不同颜色的 qtextbrowser [英] Python - pyqt5 - Set text to qtextbrowser with different colors

查看:1036
本文介绍了Python - pyqt5 - 将文本设置为具有不同颜色的 qtextbrowser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串数组,其中包含拼写正确的单词和拼写错误的单词.我想将所有这些单词设置为 qtextbrowser 并且我想让拼写错误的单词 red 颜色.

I have a String array which contains correctly spelled words and misspelled words. I want to set all those words to a qtextbrowser and I want to make misspelled words red color.

wordlist = ['correct1', 'correct2', 'incorrect1', 'correct3', 'incorrect2']

推荐答案

您可以将拼写错误的单词包裹在 html 标签中,并将内联样式设置为显示红色.

You can wrap the misspelled words in an html tag and set the inline style to display red.

def check_misspelled(self, word):
    if ...:  # check if word is misspelled here
        word = '<span style=\" color: #ff0000;\">%s</span>' % word
    self.text_browser.append(word)

这篇关于Python - pyqt5 - 将文本设置为具有不同颜色的 qtextbrowser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆