Skip to content

Commit a2bb2ef

Browse files
Fix UIntSpinBox disallowing intermediate inputs outside of range
1 parent 06b22e0 commit a2bb2ef

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/ui/uintspinbox.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,16 @@ void UIntSpinBox::onEditFinished() {
113113
// Valid input
114114
newValue = this->valueFromText(input);
115115
} else if (state == QValidator::Intermediate) {
116-
// User has deleted all the number text.
117-
// If they did this by selecting all text and then hitting delete
118-
// make sure to put the cursor back in front of the prefix.
119-
newValue = m_minimum;
120-
this->lineEdit()->setCursorPosition(m_prefix.length());
116+
if (input == m_prefix) {
117+
// User has deleted all the number text.
118+
// If they did this by selecting all text and then hitting delete
119+
// make sure to put the cursor back in front of the prefix.
120+
newValue = m_minimum;
121+
this->lineEdit()->setCursorPosition(m_prefix.length());
122+
} else {
123+
// Other intermediate inputs (values outside of acceptable range) should be ignored.
124+
return;
125+
}
121126
}
122127
if (newValue != m_value) {
123128
m_value = newValue;
@@ -160,10 +165,14 @@ QValidator::State UIntSpinBox::validate(QString &input, int &pos) const {
160165

161166
bool ok;
162167
uint32_t num = copy.toUInt(&ok, m_displayIntegerBase);
163-
if (!ok || num < m_minimum || num > m_maximum)
168+
if (!ok)
164169
return QValidator::Invalid;
165170

166171
input += copy.toUpper();
172+
173+
if (num < m_minimum || num > m_maximum)
174+
return QValidator::Intermediate;
175+
167176
return QValidator::Acceptable;
168177
}
169178

0 commit comments

Comments
 (0)