Help text color in TextEdit
Hi,
I want to make error message in TextEdit has red color, so I do like this:
Quote:
QString tag1 = "<font color = 'red'>";
tag1.append(error);
tag1.append("</font>");
read_textEdit->append(tag1);
but when I select that error message in TextEdit, all other message come up in TextEdit after it will become red. If I don't select it, all other message come up in TextEdit will become black color as default. So how can I fix it? I want only the error message has red color only. I try to do like this but it didn't fix the problem of other message become red also if I highlight the error message in TextEdit.
Quote:
QString tag1 = "<font color = 'red'>";
tag1.append(error);
tag1.append("</font><font color = 'black'></font>");
read_textEdit->append(tag1);
Re: Help text color in TextEdit
Can anyone help me on this problem?
Re: Help text color in TextEdit
I also have same problem.
Re: Help text color in TextEdit
Qt docs say:
Quote:
Note: The new paragraph appended will have the same character format and block format as the current paragraph, determined by the position of the cursor.
Try the QTextDocument API:
Code:
cur.insertText( message );
Re: Help text color in TextEdit
use this function:
Code:
{
if(s.isEmpty())
return;
QString sColor
= "<font color="+c.
name()+">";
while ( !theStream.atEnd() )
read_textEdit
->append
(QTime::currentTime().
toString() + " " + sColor
+theStream.
readLine());
//edLog->setParagraphBackgroundColor(edLog->paragraphs()-1,c);
QFile file( "[LOG FILE NAME].log" );
// Write the text to a file if ( file.open( IO_WriteOnly ) )
{
for(int i=0;i<m_log->paragraphs();i++)
stream << read_textEdit->text(i) << "\r\n";
}
file.close();
}
this function write the string s to the read_textEdit member and a log file(you do not need to use this "file code" if you do not want log file)
each time you want to write to a log file or to the read_textEdit member call this function with any color you want
Re: Help text color in TextEdit
Quote:
Originally Posted by
vql
I also have same problem.
QTextEdit not parse HTML <font tag> !
to understand QTextEdit html tag load this
http://www.qt-apps.org/content/show....?content=59493
or export html from
http://www.qt-apps.org/content/show....?content=67552
Code:
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;">
<span style=" font-weight:600; color:#ff0000;"> error on red and bold</span>
</p>