From ef876856267ba869daf02dcd590d2d0e01059ec9 Mon Sep 17 00:00:00 2001 From: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com> Date: Sat, 25 Nov 2023 13:29:48 -0500 Subject: [PATCH] Bugfix: Check min max versus current value (#221) * Check min max vs value * add test * style: [pre-commit.ci] auto fixes [...] * test min too * check that max > min per Qt * update test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/superqt/spinbox/_intspin.py | 6 ++++++ tests/test_large_int_spinbox.py | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/superqt/spinbox/_intspin.py b/src/superqt/spinbox/_intspin.py index 5ead23d6..29517684 100644 --- a/src/superqt/spinbox/_intspin.py +++ b/src/superqt/spinbox/_intspin.py @@ -65,14 +65,20 @@ def minimum(self): def setMinimum(self, min): self._minimum = int(min) + if self._minimum > self._value: + self.setValue(self._minimum) def maximum(self): return self._maximum def setMaximum(self, max): self._maximum = int(max) + if self._maximum < self._value: + self.setValue(self._maximum) def setRange(self, minimum, maximum): + if maximum < minimum: + maximum = minimum self.setMinimum(minimum) self.setMaximum(maximum) diff --git a/tests/test_large_int_spinbox.py b/tests/test_large_int_spinbox.py index d7578e16..08612c54 100644 --- a/tests/test_large_int_spinbox.py +++ b/tests/test_large_int_spinbox.py @@ -22,6 +22,24 @@ def test_large_spinbox(qtbot): assert sb.value() == -(10**e) +def test_large_spinbox_range(qtbot): + sb = QLargeIntSpinBox() + qtbot.addWidget(sb) + sb.setRange(-100, 100) + sb.setValue(50) + + sb.setRange(-10, 10) + assert sb.value() == 10 + + sb.setRange(100, 1000) + assert sb.value() == 100 + + sb.setRange(50, 0) + assert sb.minimum() == 50 + assert sb.maximum() == 50 + assert sb.value() == 50 + + def test_large_spinbox_type(qtbot): sb = QLargeIntSpinBox() qtbot.addWidget(sb)