Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Push Button -> Label, setText not refreshing under MacOS

Push Button -> Label, setText not refreshing under MacOS

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    barkingsheep
    wrote on 29 Dec 2018, 18:43 last edited by barkingsheep
    #1

    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):
            self.name = name
        def printName(self):
            return self.name
    class MyForm(QDialog):
        def __init__(self):
            super().__init__()
            self.ui = Ui_Dialog()
            self.ui.setupUi(self)
            self.ui.pushButton.clicked.connect(self.dispmessage)
            self.show()
        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()
        w.show()
        sys.exit(app.exec_())
    
    
    from PyQt5 import QtCore, QtGui, QtWidgets
    
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName("Dialog")
            Dialog.resize(400, 300)
            self.pushButton = QtWidgets.QPushButton(Dialog)
            self.pushButton.setGeometry(QtCore.QRect(250, 80, 113, 32))
            self.pushButton.setAutoDefault(False)
            self.pushButton.setDefault(False)
            self.pushButton.setFlat(False)
            self.pushButton.setObjectName("pushButton")
            self.lineEditName = QtWidgets.QLineEdit(Dialog)
            self.lineEditName.setGeometry(QtCore.QRect(120, 90, 113, 21))
            self.lineEditName.setObjectName("lineEditName")
            self.label = QtWidgets.QLabel(Dialog)
            self.label.setGeometry(QtCore.QRect(120, 40, 141, 31))
            self.label.setObjectName("label")
            self.labelResponse = QtWidgets.QLabel(Dialog)
            self.labelResponse.setGeometry(QtCore.QRect(150, 150, 60, 16))
            self.labelResponse.setObjectName("labelResponse")
    
            self.retranslateUi(Dialog)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
    
        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"))
    
    
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 29 Dec 2018, 19:25 last edited by
      #2

      Hi and welcome to the forums.
      It seems to be a real Qt problem
      https://forum.qt.io/topic/96758/qt-creator-4-6-2-on-macos-high-sierra-settext-not-working/2
      https://bugreports.qt.io/browse/QTBUG-68740
      https://bugreports.qt.io/browse/QTBUG-68521

      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();

      1 Reply Last reply
      1
      • B Offline
        B Offline
        barkingsheep
        wrote on 29 Dec 2018, 19:47 last edited by
        #3

        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.

        M 1 Reply Last reply 29 Dec 2018, 19:52
        0
        • B barkingsheep
          29 Dec 2018, 19:47

          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.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 29 Dec 2018, 19:52 last edited by
          #4

          @barkingsheep
          Hi
          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.

          1 Reply Last reply
          2
          • B Offline
            B Offline
            barkingsheep
            wrote on 29 Dec 2018, 20:41 last edited by
            #5

            Ok thanks, I downgraded to 5.10.

            pip3 install PyQt5==5.10
            
            1 Reply Last reply
            2

            4/5

            29 Dec 2018, 19:52

            • Login

            • Login or register to search.
            4 out of 5
            • First post
              4/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved