From a2bb2efa3e4bad05cdb2d3c035616c0d0d6aeaf9 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 7 Jul 2025 22:24:01 -0400 Subject: [PATCH] Fix UIntSpinBox disallowing intermediate inputs outside of range --- src/ui/uintspinbox.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/ui/uintspinbox.cpp b/src/ui/uintspinbox.cpp index 53f6df78..095d754e 100644 --- a/src/ui/uintspinbox.cpp +++ b/src/ui/uintspinbox.cpp @@ -113,11 +113,16 @@ void UIntSpinBox::onEditFinished() { // Valid input newValue = this->valueFromText(input); } else if (state == QValidator::Intermediate) { - // User has deleted all the number text. - // If they did this by selecting all text and then hitting delete - // make sure to put the cursor back in front of the prefix. - newValue = m_minimum; - this->lineEdit()->setCursorPosition(m_prefix.length()); + if (input == m_prefix) { + // User has deleted all the number text. + // If they did this by selecting all text and then hitting delete + // make sure to put the cursor back in front of the prefix. + newValue = m_minimum; + this->lineEdit()->setCursorPosition(m_prefix.length()); + } else { + // Other intermediate inputs (values outside of acceptable range) should be ignored. + return; + } } if (newValue != m_value) { m_value = newValue; @@ -160,10 +165,14 @@ QValidator::State UIntSpinBox::validate(QString &input, int &pos) const { bool ok; uint32_t num = copy.toUInt(&ok, m_displayIntegerBase); - if (!ok || num < m_minimum || num > m_maximum) + if (!ok) return QValidator::Invalid; input += copy.toUpper(); + + if (num < m_minimum || num > m_maximum) + return QValidator::Intermediate; + return QValidator::Acceptable; }