Details
-
Bug
-
Resolution: Out of scope
-
P4: Low
-
None
-
6.4.0.1
-
None
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)