PDA

View Full Version : Help text color in TextEdit



tho97
19th March 2008, 19:03
Hi,
I want to make error message in TextEdit has red color, so I do like this:

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.


QString tag1 = "<font color = 'red'>";
tag1.append(error);
tag1.append("</font><font color = 'black'></font>");
read_textEdit->append(tag1);

tho97
21st March 2008, 16:37
Can anyone help me on this problem?

vql
21st March 2008, 16:53
I also have same problem.

jacek
25th March 2008, 19:41
Qt docs say:
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:
QTextCursor cur( _ui.textEdit->document() );
cur.movePosition( QTextCursor::End, QTextCursor::MoveAnchor );
cur.insertBlock( QTextBlockFormat() );
cur.insertText( message );

Equilibrium
26th March 2008, 08:09
use this function:


void WriteLog(QString s, QColor c)
{
if(s.isEmpty())
return;

QTextStream theStream(s,IO_ReadOnly);
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 ) )
{
QTextStream stream( &file );
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

patrik08
26th March 2008, 08:47
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.php/XHTML+Wysiwyg+Qeditor?content=59493
or export html from
http://www.qt-apps.org/content/show.php/Fop+MiniScribus+XSL-Fo?content=67552




<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>