本文介紹了具有不同文本顏色的 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
框中實現(xiàn)嗎?如果沒有,獲得這種行為的最簡單方法是什么?
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);
其中 text,是 HTML 格式的文本,包含彩色線條等.
where text, is a HTML formated text, contains with colored lines and etc.
這篇關于具有不同文本顏色的 QTextEdit (Qt/C++)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!