Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2126

QDoubleSpinBox.valueChanged fires without the value having changed when setting maximum to NaN

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P4: Low
    • None
    • 6.4.0.1
    • PySide
    • None
    • Windows

    Description

      I am not sure this is a PySide bug, a Qt bug, or a non-bug. Anyway:

       

      Setting the maximum of a QDoubleSpinBox to NaN sets its value to NaN. This is not documented, but it is not documented that it does not do that, so I can kind of accept it.

       

      However, when doing so repeatedly, QDoubleSpinBox.valueChanged fires repeatedly although the value has not changed. Here's an example:

      import math
      from PySide6.QtWidgets import QApplication, QDoubleSpinBox
      
      QApplication()
      box = QDoubleSpinBox()
      box.valueChanged.connect(lambda: print("This should print only once."))
      
      # this calls value_changed as expected
      box.setMaximum(math.nan)
      
      # this calls value_changed - unexpected!
      value_before = box.value()
      box.setMaximum(math.nan)
      value_after = box.value()
      
      # reason seems to be that NaN != NaN:
      print(value_before, "!=", value_after, "?")
      print(value_after != value_before)  # True - that may be why, I guess.
      

      This can lead to nasty loops as in this example:

      import math
      import sys
      
      from PySide6.QtWidgets import QApplication, QDoubleSpinBox
      
      sys.setrecursionlimit(20)
      
      def value_changed() -> None:
          box.setMaximum(math.nan)
      
      QApplication()
      box = QDoubleSpinBox()
      box.valueChanged.connect(value_changed)
      box.setValue(1)
      

       

      Attachments

        1. pyside2126_diag.diff
          2 kB
        2. pyside2126.py
          0.8 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            bers bers bers
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes