diff options
author | Christian Heimlich <chris@pcserenity.com> | 2020-08-31 02:01:58 -0400 |
---|---|---|
committer | Christian Heimlich <chris@pcserenity.com> | 2020-09-23 20:33:33 -0400 |
commit | e1cf5b23481af9e9646f9aeb0e45a46e31e8684d (patch) | |
tree | d562ccdf575086145a2d83990abdb203b0d33883 /src/widgets/widgets/qlineedit.cpp | |
parent | 9c5698a8fcf9b890d8ed23b8e6cbab2971c8dc87 (diff) |
Fix redundant emission of editingFinished from QLineEdit with Return key
Current implementation of QLineEdit uses the "edited" bit-field flag to
prevent unnecessary emissions of editingFinished() when a line edit
loses focus but its contents have not changed since the last time the
signal was emitted; however, this flag is only cleared when the signal
is fired due to focus loss and not when the Return/Enter key is pressed.
This causes an unexpected double emission of the signal when focus is
lost following a press of the Return/Enter key if the line edit's text
was not further altered between the two actions.
This change includes the Return/Enter press as a trigger for clearing
the "edited" flag to make editingFinished()'s behavior more consistent
and expected. Prevents slots in user code from triggering twice in
situations where the line edit's current contents have already been
handled, but still allows the end-user to force an emission of the
signal via Return/Enter.
The effect of the "edited" flag on the signals behavior has also been
noted in the signal description as it was previously omitted.
[ChangeLog][QtWidgets][QLineEdit][Behavior Change] Pressing the
Return/Enter key in a QLineEdit will now also prevent editingFinished()
from firing due to focus loss if the contents of the line edit have not
changed since the last time the signal was emitted.
See - https://forum.qt.io/topic/116902/
Change-Id: I11aadd45341337b7852da8cf5802c7c9efdd614d
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/widgets/qlineedit.cpp')
-rw-r--r-- | src/widgets/widgets/qlineedit.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 07985cf966..9f1f00ced7 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -1691,8 +1691,11 @@ void QLineEdit::mouseDoubleClickEvent(QMouseEvent* e) /*! \fn void QLineEdit::editingFinished() - This signal is emitted when the Return or Enter key is pressed or - the line edit loses focus. Note that if there is a validator() or + This signal is emitted when the Return or Enter key is pressed, or + if the line edit loses focus and its contents have changed since the + last time this signal was emitted. + + Note that if there is a validator() or inputMask() set on the line edit and enter/return is pressed, the editingFinished() signal will only be emitted if the input follows the inputMask() and the validator() returns QValidator::Acceptable. |