Widgets are not updated - is this a bug?

Raymond Osborn rayosborn at mac.com
Thu Jun 25 17:04:42 BST 2020


It’s mainly the setText functions for QLabel and QLineEdit, e.g., 

class NXLabel(QtWidgets.QLabel):
    """A text label.
    
    This is being subclassed from the PyQt QLabel class because of a bug in
    recent versions of PyQt5 (>11) that requires the box to be repainted 
    after any programmatic changes.
    """

    def setText(self, text):
        """Function to set the text in the box.

        Parameters
        ----------
        text : str
            Text to replace the text box contents.
        """
        super(NXLabel, self).setText(str(text))
        self.repaint()

I also added a repaint to the setValue function of QSpinBox and QDoubleSpinBox. I presume they had also given problems, but it might have been a precaution. 

class NXSpinBox(QtWidgets.QSpinBox):

    def setValue(self, value):
        super(NXSpinBox, self).setValue(value)
        self.repaint()

It doesn’t look as if it affected QTextEdit for some reason, but there may be others that I don’t use. 

Ray

> On Jun 25, 2020, at 10:36 AM, Christian ARNAUD <carnaudfree at gmail.com> wrote:
> 
> Hi Raymond,
>  
> Thank you for your quick answers.
> Would it be possible to share how do you subclass the concerned widgets? Is there a specific method that should be overloaded to trigger the repaint event?
>  
> Christian
>  
>  
> De : Raymond Osborn <rayosborn at mac.com>
> Date : jeudi 25 juin 2020 à 15:41
> À : PyQt mailing list <pyqt at riverbankcomputing.com>
> Cc : Christian ARNAUD <carnaud at free.fr>
> Objet : Re: Widgets are not updated - is this a bug?
>  
> This is a bug that has been an issue since around v5.10 but which only affects Macs as far as I know. In my own code, I have had to subclass virtually every widget whose contents I change programmatically in order to add a call to repaint each time. Since I need my code to be compatible with multiplePyQt versions, I will have to leave it in even if it is fixed.
>  
> Ray
> 
> 
>> From: Christian ARNAUD <carnaud at free.fr <mailto:carnaud at free.fr>>
>> Subject: Widgets are not updated - is this a bug?
>> Date: June 25, 2020 at 1:46:21 AM CDT
>> To: <pyqt at riverbankcomputing.com <mailto:pyqt at riverbankcomputing.com>>
>> 
>> 
>> Hi,
>>  
>> I ran in a strange behavior where widgets in the view aren’t properly refreshed on change.
>> Here is the code, developed to show the problem:
>>  
>> import sys
>> 
>> from PyQt5 import QtWidgets
>> from PyQt5.QtCore import Qt
>> 
>> 
>> class MainWindow(QtWidgets.QMainWindow):
>>     def __init__(self):
>>         QtWidgets.QMainWindow.__init__(self)
>>         self.resize(250, 100)
>>         self.setWindowTitle("Demo")
>>         self.centralWidget = QtWidgets.QWidget(self)
>>         self.formlayout = QtWidgets.QFormLayout(self.centralWidget)
>>         self.label1 = QtWidgets.QLabel('Text 1', self.centralWidget)
>>         self.ledit1 = QtWidgets.QLineEdit('initial value', self.centralWidget)
>>         self.bproceed = QtWidgets.QPushButton('Proceed', self.centralWidget)
>>         self.bproceed.setDefault(True)
>>         self.bproceed.setFocusPolicy(Qt.StrongFocus)
>>         self.formlayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label1)
>>         self.formlayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.ledit1)
>>         self.formlayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.bproceed)
>>         self.setCentralWidget(self.centralWidget)
>> 
>>         self.bproceed.clicked.connect(self.on_clicked)
>> 
>>     def on_clicked(self):
>>         self.ledit1.setText('')
>> 
>> 
>> if __name__ == "__main__":
>>     app = QtWidgets.QApplication(sys.argv)
>>     win = MainWindow()
>>     win.show()
>>     sys.exit(app.exec())
>>  
>>  
>> If the pushbutton is clicked with the mouse or with the space key (after getting the focus with Tab), the text in the lineedit is not refreshed. If a repaint is forced, it is.
>> If the pushbutton is clicked with the enter key (after getting the focus with Tab), the text in the lineedit is correctly refreshed.
>>  
>> Any idea?
>>  
>> My env:
>> OSX Catalina 10.15.5
>> Python 3.6
>> PyQt: 15.0
>>  
>> Thank you
>> 
>> 
>> _______________________________________________
>> PyQt mailing list
>> PyQt at riverbankcomputing.com <mailto:PyQt at riverbankcomputing.com>
>> https://www.riverbankcomputing.com/mailman/listinfo/pyqt <https://www.riverbankcomputing.com/mailman/listinfo/pyqt>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200625/8ba97ae7/attachment-0001.htm>


More information about the PyQt mailing list