QTextEdit

一、设置颜色,支持html语言格式的

     ui->textEdit->append("<font color="#FF0000">红色字体</font> ");

    信息显示用到,错误的红色字体

   光标移到后面

teMsg_->moveCursor(QTextCursor::End); 
void MainWidget::slotShowMsg(MainWidget::MsgType type,QString msg)
{
    if(type==MSG_ERROR)
    {
       msg="<font color="#ff0000">"+msg+"</font>";
    }

    teMsg_->append(QDateTime::currentDateTime ().toString ("[yyyy/MM/dd hh:mm:ss zzz] ")+msg);

    logCount_++;
    if(logCount_>LOG_MAX_SIZE)
    {
        teMsg_->clear();
        logCount_=0;
        //qDebug()<<"clear";
    }

    teMsg_->moveCursor(QTextCursor::End);


}
原文地址:https://www.cnblogs.com/ike_li/p/12432882.html