Widgets are not updated - is this a bug?

Christian ARNAUD carnaud at free.fr
Thu Jun 25 07:46:21 BST 2020


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200625/803cf74a/attachment-0001.htm>


More information about the PyQt mailing list