本文介紹了具有不同文本顏色的 QTextEdit (Qt/C++)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我有一個(gè)顯示文本的 QTextEdit
框,我希望能夠在同一個(gè) QTextEdit
框中為不同的文本行設(shè)置文本顏色.(即第 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
框中實(shí)現(xiàn)嗎?如果沒(méi)有,獲得這種行為的最簡(jiǎ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.
這篇關(guān)于具有不同文本顏色的 QTextEdit (Qt/C++)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!