在添加文本之前查询滚动条
QScrollBar *scrollbar = ui->text_accept->verticalScrollBar();
bool scrollbarAtBottom = (scrollbar->value() >= (scrollbar->maximum() - 50));
int scrollbarPrevValue = scrollbar->value();
QTextCursor cursor = ui->text_accept->textCursor();//将光标移动到文本末尾
cursor.movePosition(QTextCursor::End);
ui->text_accept->setTextCursor(cursor);
ui->text_accept->setFontPointSize(10);
ui->text_accept->insertPlainText(str.toUpper());
if (scrollbarAtBottom)
ui->text_accept->ensureCursorVisible();
else
ui->text_accept->verticalScrollBar()->setValue(scrollbarPrevValue);