PySide QWidget 立即更新
在我的应用程序中,我调用了一个外部模块,该模块生成一些线程,执行一些操作,然后返回一个值。我试图让 QMessageBox 在之前显示,并让 QLabel 在之后更新完成,但我被难住了。代码如下(从按钮上的 QObject.connect 调用):
def _process(self):
self._message_box.show()
for i in range(3):
rv = external_module_function_with_threads() // blocking function call
label = getattr(self, "label%d" % (i + 1))
label.setText(rv)
当我单击按钮并调用该函数时,消息框仅在循环完成后显示。标签也仅在循环完成后更新。我尝试在循环中调用 label.repaint() ,但似乎所做的只是让消息框更早显示(但其中没有文本)。
我知道我没有违反“主线程外部的 GUI 操作”规则(...对吗?),那么有没有办法强制更新?
In my application, I have a call to an external module which spawns some threads, does some stuff, then returns a value. I'm trying to get a QMessageBox to show before and a QLabel to update after this is complete, but I'm stumped. The code goes something like this (called from QObject.connect on a button):
def _process(self):
self._message_box.show()
for i in range(3):
rv = external_module_function_with_threads() // blocking function call
label = getattr(self, "label%d" % (i + 1))
label.setText(rv)
When I click the button and the function is called, the message box only shows after the loop completes. The labels only update after the loop completes as well. I tried calling label.repaint() in the loop, but all that seems to do is make the message box show up earlier (but with no text in it).
I know I'm not violating the "GUI operations from outside the main thread" rule (...right?), so is there a way to force an update?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于消息框,请使用
self._message_box.exec_()
。根据我对你问题的理解,我认为这会达到你想要的效果。For your message box use
self._message_box.exec_()
. From my understanding of your question, I think this will do what you want.