简体   繁体   English

PyQt Label 不更改文本

[英]PyQt Label not changing text

I have this code running on a PyQt window on windows:我在 windows 上的 PyQt window 上运行此代码:

    try:
        self.actorUser.findIdfFiles(pathToFolder)
        msg = "Processando arquivos..."
        self.processingLabel.setText(msg)

        self.actorUser.runSimulation(pathToFolder, pathToEpw)

Inside the "runSimulation" code I start a subprocess using the method "call".在“runSimulation”代码中,我使用方法“call”启动了一个子进程。 This blocks my GUI and at the title of the window appears "Python stopping responding", but if I wait a little bit the subprocess finishes normally, and the label is finally changed.这会阻止我的 GUI,并且在 window 的标题处出现“Python 停止响应”,但是如果我稍等片刻,子进程会正常完成,并且 label 最终会更改。 But what I want is that the label have is text really changed before the subprocess started.但我想要的是 label 的文本在子进程开始之前确实发生了变化。 What can I do??我能做什么??

Qt (and most UI frameworks) don't update the display as soon as values are set, only when they are told to repaint. Qt(和大多数UI框架)不会在设置值后立即更新显示,只有在告诉它们重新绘制时才更新。

What you need to do is add a call 您需要做的就是添加通话

QtGui.QApplication.processEvents()

before your long-running subprocess, to make it process all pending events. 在您长期运行的子流程之前,使其可以处理所有未决事件。

Joe P 's answer is quite right. Joe P 的回答很正确。 But this method is change to但是这个方法改成

QtCore.QCoreApplication.processEvents()

in pyqt5在 pyqt5

link: https://doc.qt.io/qt-5/qcoreapplication.html#processEvents链接: https://doc.qt.io/qt-5/qcoreapplication.html#processEvents

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM