Changing a single strings color within a QTextEdit

后端 未结 3 1566
春和景丽
春和景丽 2021-02-06 03:10

I am working on a GUI developed via PyQt and Qt4. Within my GUI I have a QTextEdit that has various data written to. Is there a way in which I can manipulate the color of one wo

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-06 03:49

    You should provide a rich text for it. It can be done by creating a tag and setting the color property to an RGB value :

    redText = ""
    redText.append("I want this text red")
    redText.append("")
    self.myTextEdit.write(redText)
    
    blackText = ""
    blackText.append("And this text black")
    blackText.append("")
    self.myTextEdit.append(blackText)
    

提交回复
热议问题