Unsolved QSpinBox.setValue doesn't redraw window properly
-
I am using pyqt 5.12.3 from anaconda on osx Catalina
This problem seems to be specific to mac as I do not see it on Linux (do not have a windows system to test)Updating a QSpinBox by calling setValue does not seem to properly delete previous content which is only partially drawn over. Switching to another desktop and back does seem to force a redraw, also clicking with the mouse inside the box.
Example (set value of 8 over previous 0)
Any ideas if this is a known problem or if I'm doing something wrong in the code?
Thanks
This is a minimal python file:
import sys from PyQt5 import QtWidgets, QtCore class MainWindow(QtWidgets.QMainWindow): def __init__(self, ): super().__init__() self.spin = QtWidgets.QSpinBox(self) self.spin.move(50,50) self.button = QtWidgets.QPushButton('button', self) self.button.move(50, 100) self.button.clicked.connect(self.on_click) def on_click(self): v = self.spin.value() if v == 0: self.spin.setValue(8) else: self.spin.setValue(0) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())
-
For anyone who comes across this... I could not reproduce the issue with PyQt 5.12.6 and OSX 10.15.5, but if I add a second button to go after the the spinbox in the layout, then I can reproduce:
import sys from PyQt5 import QtWidgets, QtCore print(QtCore.QT_VERSION_STR) class MainWindow(QtWidgets.QWidget): def __init__(self, ): super().__init__() self.spin = QtWidgets.QSpinBox(self) self.button = QtWidgets.QPushButton('button', self) self.button.clicked.connect(self.on_click) self.button2 = QtWidgets.QPushButton('do nothing', self) VBox = QtWidgets.QVBoxLayout() VBox.addWidget(self.button) VBox.addWidget(self.spin) VBox.addWidget(self.button2) self.setLayout(VBox) def on_click(self): v = self.spin.value() if v == 0: self.spin.setValue(8) else: self.spin.setValue(0) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())
Then I was able to "fix" / "workaround" the issue by adding
type=QtCore.Qt.QueuedConnection
in theconnect
call, i.e. this:self.button.clicked.connect(self.on_click, type=QtCore.Qt.QueuedConnection)
-
This might be related to https://bugreports.qt.io/browse/PYSIDE-871