如何实时更新 QTextEdit [英] How to update a QTextEdit in real-time
本文介绍了如何实时更新 QTextEdit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有 QtextEdit 的 UI,
(1) 我想更新 QtextEdit 并且主 UI 可以实时显示并且不会卡住.使用 sleep 时,无法按我的意愿工作.(2)我想制作一个函数并传递参数给它,QtestEdit可以实时更新显示
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")
推荐答案
尝试使用 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.
这篇关于如何实时更新 QTextEdit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文