diff options
author | Doris Verria <doris.verria@qt.io> | 2023-09-18 10:41:34 +0200 |
---|---|---|
committer | Doris Verria <doris.verria@qt.io> | 2023-09-25 15:12:05 +0200 |
commit | faae3dc6b15e3d8754b15a7cfb22b6a797fd2e36 (patch) | |
tree | 63d08e06b9e058c9e6b1afb6ff599425cdd652e4 /src/widgets/itemviews | |
parent | 66be69139ce15be5df800e93a4702891fa8d6fb3 (diff) |
QAbstractItemDelegate: Update spinbox editor value before committing
QAbstractItemView installs the delegate as an event filter on the
editor, so the delegate will get the focusOut event (and other
events) before the editor does. QAbstractItemDelegate will then
emit commitData, signaling that the "updated" data should be
written back to the model.
In the case where the editor of a delegate (QAbstractItemDelegate)
is a QSpinBox with keyboardTracking set to false, the value of
the spinbox won't be updated while typing, but only when the
spinbox's text edit focus is lost. In this case, the delegate's
commitData will be emitted before the spinbox has had a chance
to update the value in its handling of the focusOut event.
To fix, make sure to update the value before the data is
committed to the model in the delegate's tryFixup method.
Fixes: QTBUG-116926
Pick-to: 6.5 6.6
Change-Id: I68540964342407d23387e4404a0fe3f00d80eb5f
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qabstractitemdelegate.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp index 59caed1699..23e8ef0901 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.cpp +++ b/src/widgets/itemviews/qabstractitemdelegate.cpp @@ -514,6 +514,14 @@ bool QAbstractItemDelegatePrivate::tryFixup(QWidget *editor) return e->hasAcceptableInput(); } } +#endif +#if QT_CONFIG(spinbox) + // Give a chance to the spinbox to interpret the text and emit + // the appropriate signals before committing data. + if (QAbstractSpinBox *sb = qobject_cast<QAbstractSpinBox *>(editor)) { + if (!sb->keyboardTracking()) + sb->interpretText(); + } #else Q_UNUSED(editor); #endif // QT_CONFIG(lineedit) |