nsvinc
29th December 2015, 12:00
Hello,
I'm looking for a solution to append single characters to QTextEdit with different colors.
I tried the following:
QTextCursor curs(textCursor());
QTextCharFormat fmt;
fmt.setForeground(QBrush(Qt::red));
curs.setCharFormat(fmt);
curs.movePosition(QTextCursor::End);
curs.insertText(QString(chr));
does not work
setTextColor(kolor1);
append(QString(chr));
does not work either
The only thing that actually works, is the <font> tag
append(QString("<font color=red>%1</font>").arg(chr));
The problem is, I'm getting the input char by char, and cannot combine it into QString easily; every new character could have a different color. I would like to find a way other than tagging every single character (which would yield tons of garbage text not seen by the user, and would be probably not speed efficient).
It would be nice, if QTextEdit remembers the last color setting, and appends new characters with that color...
I'm looking for a solution to append single characters to QTextEdit with different colors.
I tried the following:
QTextCursor curs(textCursor());
QTextCharFormat fmt;
fmt.setForeground(QBrush(Qt::red));
curs.setCharFormat(fmt);
curs.movePosition(QTextCursor::End);
curs.insertText(QString(chr));
does not work
setTextColor(kolor1);
append(QString(chr));
does not work either
The only thing that actually works, is the <font> tag
append(QString("<font color=red>%1</font>").arg(chr));
The problem is, I'm getting the input char by char, and cannot combine it into QString easily; every new character could have a different color. I would like to find a way other than tagging every single character (which would yield tons of garbage text not seen by the user, and would be probably not speed efficient).
It would be nice, if QTextEdit remembers the last color setting, and appends new characters with that color...