Important: Please read the Qt Code of Conduct -

Push Button -> Label, setText not refreshing under MacOS

  • I have tested this on several MacOS Mojave machines running Python 3.72 and PyQt5 5.11.3 and they all have the same issue with my (very simple) code that the designated function of the pushButton does not refresh the label automatically, but only after de-focusing the PyQt Window, e.g. by moving to another desktop or application.

    Same code under Windows10 runs flawlessly. I would love some help as my Mac is my main coding machine and I am eager to continue my QtJourney!

    edit: I have further information. The clicking of the pushButton seems to be the issue. When I am in the lineEdit and hit enter, the label changes without problems.

    import sys
    from PyQt5.QtWidgets import QDialog, QApplication
    from Ui_dialog import *
    class Student:
        name = ""
        def __init__(self, name):
   = name
        def printName(self):
    class MyForm(QDialog):
        def __init__(self):
            self.ui = Ui_Dialog()
        def dispmessage(self):
            studentObj = Student(self.ui.lineEditName.text())
            self.ui.labelResponse.setText("Hello " + studentObj.printName())
    if __name__=="__main__":
        app = QApplication(sys.argv)
        w = MyForm()
    from PyQt5 import QtCore, QtGui, QtWidgets
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.resize(400, 300)
            self.pushButton = QtWidgets.QPushButton(Dialog)
            self.pushButton.setGeometry(QtCore.QRect(250, 80, 113, 32))
            self.lineEditName = QtWidgets.QLineEdit(Dialog)
            self.lineEditName.setGeometry(QtCore.QRect(120, 90, 113, 21))
            self.label = QtWidgets.QLabel(Dialog)
            self.label.setGeometry(QtCore.QRect(120, 40, 141, 31))
            self.labelResponse = QtWidgets.QLabel(Dialog)
            self.labelResponse.setGeometry(QtCore.QRect(150, 150, 60, 16))
        def retranslateUi(self, Dialog):
            _translate = QtCore.QCoreApplication.translate
            Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
            self.pushButton.setText(_translate("Dialog", "Click"))
            self.label.setText(_translate("Dialog", "Enter your name"))
            self.labelResponse.setText(_translate("Dialog", "TextLabel"))

  • Lifetime Qt Champion

    Hi and welcome to the forums.
    It seems to be a real Qt problem

    It might be fixed in Qt5.11.2 but if PyQt5 5.11.3 is same versioning
    it ought to be fixed already.

    As far as i know, a workaround is to call label->repaint();

  • Thanks for the answer and kind welcome.

    This is exactly the issue, though in Python a repaint() method does not exist afaik.

    One thread mentions it being fixed, but in my case with 5.11.3 it is not. Is there any way to upgrade to 5.12.0 through pip. I haven't found any way, only PySide2 which is something different though.

  • Lifetime Qt Champion

    Sorry, im more on the c++ side so Im not sure if you can pip upgrade.
    Would it be possible to get a PyQt5 5.10 ?
    It sounds to me it didnt have the redraw issue.

  • Ok thanks, I downgraded to 5.10.

    pip3 install PyQt5==5.10

Log in to reply