【PYQT5】textEdit添加内容,滚动条自动向下

class Main(QWidget, Ui_Form):

    def __init__(self):
        super(Main, self).__init__()
        self.setupUi(self)

        QTimer.singleShot(0, self.thread_check)  # 延迟执行 self.thread_check函数

    # 向下执行向下滚动字体函数
    def append_text_and_scroll(self,text):
        self.textEdit.append(text)
        self.textEdit.ensureCursorVisible()
    
    # 添加内容函数
    def thread_check():
        # 逻辑操作后执行添加内容
        self.append_text_and_scroll("添加内容")     


if __name__ == "__main__":
    app = QApplication(sys.argv)
    ui = Main()
    ui.show()
    # 滚动条自动下降
    for i in range(10):
        QApplication.processEvents()
    sys.exit(app.exec_())
posted @ 2023-08-13 14:52  PythonNew_Mr.Wang  Views(604)  Comments(0)    收藏  举报