1 void ThreadExit::onTaskPerformState(const QString& strStatus) 2 { 3 //追加文本(ui.taskStatusTextEdit是一个QPlainTextEdit对象) 4 auto workCursor = ui.taskStatusTextEdit->textCursor(); 5 workCursor.movePosition(QTextCursor::End); 6 workCursor.insertText(strStatus); 7 workCursor.insertBlock(); 8 9 //移动滚动条到底部 10 QScrollBar *scrollbar = ui.taskStatusTextEdit->verticalScrollBar(); 11 if (scrollbar) 12 { 13 scrollbar->setSliderPosition(scrollbar->maximum()); 14 } 15 16 }