Home > Net >  Partially coloring text of QTreeWidgetItem
Partially coloring text of QTreeWidgetItem

Time:11-10

I am trying to get part of the text of a QTreeWidgetItem to be set to red and have found a few examples, namely cmd line output

as I expect, but the actual widget gives me

widget output

where it is not recognizing the ANSI color command. I think I've set up the setItemWidget() call correctly but I could be wrong.

Thanks in advanced!

CodePudding user response:

QLabel does not support ANSI color commands. You should use Qt's HTML subset (rich text) instead:

mixedLabel.setText("I AM <span style='color: red'>CHILD</span>")

Documentation for the capabilities of their HTML subset can be found here: https://doc.qt.io/qt-6/richtext-html-subset.html

  • Related