It's been a long time, and it's finally out. Qt comes with the help system is really good, the online search for so long data, also did not find specific or vague solution. Just say with HTML or with Qtextformat and various derived classes to change the character format in the text box, nnd, brother also know can use this to achieve. There is no more concrete. Cut the crap, record it, and you'll need it later. The format is used here. The specific function is to modify the line of the cursor in the first POS character format, where the format is to give the word multibyte underline. Other formats, such as character color and background color, are the same, so change format.
voidWidget:: Setcharcolor (unsigned intPOS)
{
if (Pos<=0) return ;
Qtextcursorcursor=UI,view1->textcursor ();
Cursor.moveposition (qtextcursor::startofline); //Beginning of the line
Cursor.moveposition (qtextcursor::Right,qtextcursor:: Moveanchor,pos-1); //Move right to POS
Cursor.moveposition (qtextcursor::nextcharacter,qtextcursor ::keepanchor);
UI,view1->settextcursor (cursor); //added
Qtextcharformatdefcharfmt=UI,view1- Currentcharformat ();
Qtextcharformatnewcharfmt=defcharfmt;
Newcharfmt.setfontunderline (true);
Newcharfmt.setunderlinecolor (qcolor(Qt::red) );
Newcharfmt.setunderlinestyle (qtextcharformat::singleunderline);
UI,view1->setcurrentcharformat (newcharfmt);
Cursor.moveposition (qtextcursor::previouscharacter); //Add this sentence to remove the cursor selected
UI,view1->settextcursor (cursor); //added
ui->view1->setcurrentcharformat (defcharfmt) ;
UI,view1->setfocus ();
}
Common formats:
"Newcharfmt.setbackground (qcolor(" #EEEE00 "));"
"Newcharfmt.setfontpointsize (fontSize);"
"Newcharfmt.setfontweight (qfont::Bold);"
"Highlightedformat.setbackground (Qt::yellow);"
"Newcharfmt.setforeground (Qt::red);"
Note:"The above operation will promote the TextChanged slot function, so use the slot function when the attention, add a sign to judge the better"
Description:"curso.movepositon,,,//plus this sentence ... ed"
When not added, the effect is as follows:
Add the effect as follows:
Report:
Copyright NOTICE: This article for Bo Master [original] article, without BO Master permission can be reproduced, annotated blog Source: [Http://blog.csdn.net/FreeApe]
QT---Set a character format in a TextEdit text box