Changing a single strings color within a QTextEdit

后端 未结 3 1547
春和景丽
春和景丽 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条回答
  •  萌比男神i
    2021-02-06 03:40

    The answer of Nejat works for me by replacing ".append()" with "+=" :

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

提交回复
热议问题