Automatic drop-down of Qscrollarea in QT

Source: Internet
Author: User

A log watch box is required to make a recent project. I used Qtextedit to display my log information, but I found that every time I append my content, the scroll bar in Qtextedit does not pull down automatically, it is troublesome to pull it down every time. Found some information to achieve it. Today to summarize, there are deficiencies in the place, the trouble we point out, together with progress.

1 Create Qtextedit object void Customclass::inittextedit ()
{
M_ptextedit = new Qtextedit (this);
Connect (M_ptextedit, SIGNAL (textChanged ()), this, SLOT (Onautoscroll ()));
}

2 The following two methods can be used to implement the automatic drop-down method of the scroll bar : Directly set the value of the vertical scrollbar of the Qtextedit object (remember to add a header file when using #include <QAbstractScrollArea>)
void Customclass::onautoscroll ()
{
M_ptextedit->verticalscrollbar ()->setvalue (M_ptextedit->verticalscrollbar ()->maximum ());
}


Method Two: Modify the Qtextedit text cursor to implement the ScrollBar drop-down (remember to add a header file when using #include<qtextcursor>)
void Customclass::onautoscroll ()
{
Qtextcursor cursor = M_ptextedit->textcursor ();
Cursor.moveposition (Qtextcursor::end);
M_ptextedit->settextcursor (cursor);

}

This way, when M_ptextedit calls the Append () function, the scroll bar will automatically drop down.

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.