The QString class provides a Unicode character string
QString isn't responsible for the way it is displayed. Is is just a convinient container for the characters with a bunch of useful features. The way QString is shown depends on the widget which displays it. In your case it is QTextEdit.
//The string you want to decorate
//The widget, which will display string
//Format first 4 characters
QString redPart
= QString("<span style=" color
:#ff0000;">%1</span>").arg(s.left(4)); //Format the rest of the characters
QString greenPart
= QString("<span style=" color
:#00ff00;">%1</span>").arg(s.mid(5)); //Make resulting HTML appear on the QTextEdit
te.setHtml(redPart + greenPart);
//The string you want to decorate
QString s = "adadsfdafds";
//The widget, which will display string
QTextEdit te;
//Format first 4 characters
QString redPart = QString("<span style=" color:#ff0000;">%1</span>").arg(s.left(4));
//Format the rest of the characters
QString greenPart = QString("<span style=" color:#00ff00;">%1</span>").arg(s.mid(5));
//Make resulting HTML appear on the QTextEdit
te.setHtml(redPart + greenPart);
To copy to clipboard, switch view to plain text mode
Bookmarks