I am trying to get part of the text of a QTreeWidgetItem to be set to red and have found a few examples, namely
as I expect, but the actual widget gives me
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