Hello,
I'm looking for a solution to append single characters to QTextEdit with different colors.
I tried the following:
fmt.
setForeground(QBrush(Qt
::red));
curs.setCharFormat(fmt);
QTextCursor curs(textCursor());
QTextCharFormat fmt;
fmt.setForeground(QBrush(Qt::red));
curs.setCharFormat(fmt);
curs.movePosition(QTextCursor::End);
curs.insertText(QString(chr));
To copy to clipboard, switch view to plain text mode
does not work
setTextColor(kolor1);
setTextColor(kolor1);
append(QString(chr));
To copy to clipboard, switch view to plain text mode
does not work either
The only thing that actually works, is the <font> tag
append
(QString("<font color=red>%1</font>").
arg(chr
));
append(QString("<font color=red>%1</font>").arg(chr));
To copy to clipboard, switch view to plain text mode
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...
Bookmarks