1. 程式人生 > >Qt之textedit設定字型顏色

Qt之textedit設定字型顏色

QString str;
 
    if (type == 0) {
        str = ">> 傳送 :";
        ui->txtMain->setTextColor(QColor(100, 184, 255));
    } else if (type == 1) {
        str = "<< 接收 :";
        ui->txtMain->setTextColor(QColor(255, 107, 107));
    } else if (type == 2) {
        str = ">> 延時 :";
        ui->txtMain->setTextColor(QColor("gray"));
    } else if (type == 3) {
        str = ">> 狀態回覆 :";
        ui->txtMain->setTextColor(QColor(QUIConfig::HighColor));
    } else if (type == 4) {
        str = ">> 地址回覆 :";
        ui->txtMain->setTextColor(QColor(QUIConfig::HighColor));
    }
 
    ui->txtMain->append(QString("時間[%1] %2 %3").arg(TIMEMS).arg(str).arg(msg));
    currentMsgCount++;
}