zoukankan      html  css  js  c++  java
  • 记录QTextEdit

    一、代码如下:

        //设置行间距
        QTextBlockFormat blockFormat;
        blockFormat.setLineHeight(10, QTextBlockFormat::LineDistanceHeight);
        auto textCursor = ui->textEdit->textCursor();
        textCursor.setBlockFormat(blockFormat);
        ui->textEdit->setTextCursor(textCursor);
        //注意:append和insertHtml函数无法在首行加上空行(会自动去除空白字符串。),文本中间的多个空白字符串会被全部删除或保留一个。
    //    ui->textEdit->setLineWrapMode(QTextEdit::NoWrap); //文本不换行
    //    ui->textEdit->setReadOnly(true); //日志框设置只读属性
        QString title= "日志信息";
        QString info1 = "2020.01.01 20:15:38    启动软件,系统初始化                         a";
        QString info2 = "2020.01.01 20:15:38    软件初始化完成,准备连接服务器";
        QString info3 = "2020.01.01 20:15:38    软件已就绪";
        QString info4 = "2020.01.01 20:15:38    变频接收机1输入通道故障,故障码404";
        QString info5 = "2020.01.01 20:15:38    变频接收机1输出通道1故障,故障码405";
        QString info6 = "2020.01.01 20:15:38    滤波器输出通道7离线中";
        QString info7 = "2020.01.01 20:15:38    滤波器输出通道8离线中";
        ui->textEdit->insertPlainText(" 
    "); //可以读取换行符号
        ui->textEdit->insertPlainText("hah   hsjhd"); //从当前光标处插入文本,可以插入空白字符,且不会被省略
        ui->textEdit->append(QString("<font size=16px color="#00DBFF">%1</font>").arg(title));
        ui->textEdit->append(QString("<font size=20px color="Qt::blue"></font>")); //空行
        ui->textEdit->append(QString("<font size=14px color="Qt::blue">%1</font>").arg(info1));
        ui->textEdit->append(QString("<font size=14px color="Qt::blue">%1</font>").arg(info2));
        ui->textEdit->append(QString("<font size=14px color="Qt::blue">%1</font>").arg(info3));
        ui->textEdit->append(QString("<font size=14px color="#FF0000">%1</font>").arg(info4));
        ui->textEdit->append(QString("<font size=14px color="#FF0000">%1</font>").arg(info5));
        ui->textEdit->insertHtml("<p></p>"); //空行
        ui->textEdit->append(QString("<font size=14px color="#E3E512">%1</font>").arg(info6));

    二、运行结果:

    坚持成就伟大
  • 相关阅读:
    基本MVVM 和 ICommand用法举例(转)
    WPF C# 命令的运行机制
    628. Maximum Product of Three Numbers
    605. Can Place Flowers
    581. Shortest Unsorted Continuous Subarray
    152. Maximum Product Subarray
    216. Combination Sum III
    448. Find All Numbers Disappeared in an Array
    268. Missing Number
    414. Third Maximum Number
  • 原文地址:https://www.cnblogs.com/xian-yongchao/p/13894253.html
Copyright © 2011-2022 走看看