QmlDesigner: Fix SpinBox value reset on focus loss

Task-number: QDS-9770
Change-Id: I8a4d73e7abe8dbb5c62c571fc9980a0f78a5f819
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Henning Gruendl
2023-04-26 17:07:32 +02:00
committed by Henning Gründl
parent 8401dc64b5
commit ba91f9e3e0

View File

@@ -121,7 +121,7 @@ T.SpinBox {
height: control.spinBoxIndicatorVisible ? control.__spinBoxIndicatorHeight : 0
realEnabled: (control.realFrom < control.realTo) ? (control.realValue < control.realTo)
: (control.realValue > control.realTo)
: (control.realValue > control.realTo)
}
down.indicator: RealSpinBoxIndicator {
@@ -138,7 +138,7 @@ T.SpinBox {
height: control.spinBoxIndicatorVisible ? control.__spinBoxIndicatorHeight : 0
realEnabled: (control.realFrom < control.realTo) ? (control.realValue > control.realFrom)
: (control.realValue < control.realFrom)
: (control.realValue < control.realFrom)
}
contentItem: RealSpinBoxInput {
@@ -284,26 +284,26 @@ T.SpinBox {
control.setRealValue(control.realValue) // sanitize and clamp realValue
spinBoxInput.text = control.textFromValue(control.realValue, control.locale)
control.value = 0 // Without setting value back to 0, it can happen that one of
// the indicator will be disabled due to range logic.
// the indicator will be disabled due to range logic.
}
onRealValueModified: myTimer.restart()
onFocusChanged: {
if (control.focus) {
if (control.focus)
control.dirty = false
} else {
// Make sure displayed value is correct after focus loss, as onEditingFinished
// doesn't trigger when value is something validator doesn't accept.
spinBoxInput.text = control.textFromValue(control.realValue, control.locale)
if (control.dirty)
spinBoxInput.handleEditingFinished()
}
}
onDisplayTextChanged: spinBoxInput.text = control.displayText
onActiveFocusChanged: {
if (control.activeFocus) { // QTBUG-75862 && mySpinBox.focusReason === Qt.TabFocusReason)
control.preFocusText = spinBoxInput.text
spinBoxInput.selectAll()
} else {
// Make sure displayed value is correct after focus loss, as onEditingFinished
// doesn't trigger when value is something validator doesn't accept.
if (spinBoxInput.text === "")
spinBoxInput.text = control.textFromValue(control.realValue, control.locale)
if (control.dirty)
spinBoxInput.handleEditingFinished()
}
}
@@ -373,8 +373,8 @@ T.SpinBox {
value = Math.round(value)
control.realValue = control.clamp(value,
control.validator.bottom,
control.validator.top)
control.validator.bottom,
control.validator.top)
}
function realDecrease() {