Hi and welcome
You can use html with QTExtEdit
http://stackoverflow.com/questions/2857864/qtextedit-with-different-text-colors-qt-c
but its huge work to make code editor.
Maybe consider use a premade component ?
Scintilla is used in many projects.
https://www.riverbankcomputing.com/software/qscintilla/intro
https://www.riverbankcomputing.com/software/qscintilla/download