Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QSpinBox.setValue doesn't redraw window properly
Forum Update on Monday, May 27th 2025

QSpinBox.setValue doesn't redraw window properly

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 4 Posters 777 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.
  • L Offline
    L Offline
    laughingrice
    wrote on last edited by laughingrice
    #1

    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)

    Screenshot 2019-11-02 14.18.03.png

    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_())
    
    1 Reply Last reply
    0
    • K Offline
      K Offline
      kitchoi
      wrote on last edited by
      #2

      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 the connect call, i.e. this:

              self.button.clicked.connect(self.on_click, type=QtCore.Qt.QueuedConnection)
      
      1 Reply Last reply
      0
      • jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by
        #3

        This might be related to https://bugreports.qt.io/browse/PYSIDE-871

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        1

        • Login

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