Using Qtextedit to implement status information display boxes

Source: Internet
Author: User

To implement the status information display box using Qtextedit:

1, using qtexttable, organization status information

2, when the status information reaches a certain amount, the first record is automatically deleted. (For this check for a long time Qtextedit delete content method to achieve this function, so leave this record, for reuse. )

void mainwindow::onstatusinfo (int flag,qstring msg) {QString text;
    Qtextcharformat chfmt;
        Set Status information label switch (flag) {Case 1:text = "info";
        Chfmt.setforeground (Qbrush (qt::black));
    Break
        Case 2:text = "WARN";
        Chfmt.setforeground (Qbrush (Qt::yellow));
    Break
        Case 3:text = "ERROR";
        Chfmt.setforeground (Qbrush (qt::red));
    Break
    Default:break;
    }//Append status information after the label text.append ("" +msg);
    Set the insertion position to Qtextedit last line qtextcursor cur = ui->statustextediter->textcursor ();
    Cur.moveposition (Qtextcursor::end);
    Qtexttabelformate tableformate;
    Tableformate.setborder (0);
    Insert table for displaying status information qtexttable *table = cur.inserttable (2,1,tableformate);
    Table->cellat (0,0). Firstcursorposition (). InsertText ("[" +qtime::currenttime (). toString ("Hh:mm:ss") + "]");
    Table->cellat (1,0). Firstcursorposition (). InsertText (text); Cur.moveposition (qtextcursor::endofblock,qtextcursor::keepanchor,1);
    Cur.select (Qtextcursor::blockundercursor);
    Cur.mergecharformat (CHFMT);
    Cur.clearselection ();
    Qscrollbar *bar = Ui->statustextedit->verticalscrollbar ();
    Bar->setvalue (Bar->maximum ());
    Number of status information +1 M_status_count + +; If the number of messages is >50, delete the oldest record if (M_status_count >50) {//Move the selection cursor to the first character cur.setposition (1,qtextcursor:
        : Moveanchor);
        Select the first table Cur.moveposition (qtextcursor::endofblock,qtextcursor::keepanchor,1) containing the earliest state information;
        Cur.select (Qtextcursor::blockundercursor);
        Delete this information cur.removeselectedtext ();
        The cursor moves to the last line of Qtextedit cur.moveposition (Qtextcursor::end,qtextcursor::moveanchor);
    M_status_count--; }

}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.