QTextEdit有不同的文字颜色(Qt / C ++) [英] QTextEdit with different text colors (Qt / C++)
本文介绍了QTextEdit有不同的文字颜色(Qt / C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 QTextEdit
框显示文本,我想能够设置不同行的文本颜色在同一个 QTextEdit
框。 (例如,第1行可能是红色,第2行可能是黑色等)
I have a QTextEdit
box that displays text, and I'd like to be able to set the text color for different lines of text in the same QTextEdit
box. (i.e. line 1 might be red, line 2 might be black, etc.)
这是可能的在 QTextEdit
框?如果没有,最简单的方法是获得这个行为?
Is this possible in a QTextEdit
box? If not, what's the easiest way to get this behavior?
谢谢。
推荐答案
使用格式化为HTML的文本,例如:
Use text formated as HTML, for example:
textEdit->setHtml(text);
其中文字是HTML格式的文字,等等。
where text, is a HTML formated text, contains with colored lines and etc.
这篇关于QTextEdit有不同的文字颜色(Qt / C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文