How to update a QTextEdit in real-time

左心房为你撑大大i 提交于 2019-12-02 15:31:51

问题


i have one UI with QtextEdit,
(1) i want to update QtextEdit and main UI can display realtime and no stuck. when use sleep ,not work as i want. (2) i want have make one function and pass parameter to it, and the QtestEdit can update display real time

self.pButton_torun.clicked.connect(self.mytodo)

 def mytodo(self):
        self.progress_textEdit.append(u"==== 20 % first step finish")
        #after 2 sec
        self.progress_textEdit.append(u"==== 40 % second step finish")
        #after 2 sec
        self.progress_textEdit.append(u"==== 60 % third step finish")
        #after 2 sec
        self.progress_textEdit.append(u"==== 80 % forth step finish")

回答1:


Try using processEvents():

def mytodo(self):
    self.progress_textEdit.append(u"==== 20 % first step finish")
    QApplication.processEvents()
    # etc...

This is a bit of a workaround though, down the track you might also want to consider using separate threads.



来源:https://stackoverflow.com/questions/26581126/how-to-update-a-qtextedit-in-real-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!