Skip to content

Commit

Permalink
Bugfix: Check min max versus current value (#221)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
psobolewskiPhD and pre-commit-ci[bot] authored Nov 25, 2023
1 parent b927159 commit ef87685
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/superqt/spinbox/_intspin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 18 additions & 0 deletions tests/test_large_int_spinbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ef87685

Please sign in to comment.