From ba91f9e3e08a90164403f959b5c778dd8f109f76 Mon Sep 17 00:00:00 2001 From: Henning Gruendl Date: Wed, 26 Apr 2023 17:07:32 +0200 Subject: QmlDesigner: Fix SpinBox value reset on focus loss Task-number: QDS-9770 Change-Id: I8a4d73e7abe8dbb5c62c571fc9980a0f78a5f819 Reviewed-by: Thomas Hartmann --- .../imports/StudioControls/RealSpinBox.qml | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/RealSpinBox.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/RealSpinBox.qml index aba99f75ff..2f219a411d 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/RealSpinBox.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/RealSpinBox.qml @@ -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() { -- cgit v1.2.3