summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2018-06-05 10:42:51 +0200
committerAndy Shaw <andy.shaw@qt.io>2018-06-06 19:47:53 +0000
commitaf4435c5f8748a0135a06f7e85d979604b7eaffe (patch)
tree778be19088364ad1ac7622f39b820d59d9306920 /src
parent792298e42d99fe0251608381ea751ab85154d6be (diff)
QLineEdit: Emit inputRejected() when part of the input is rejected
When pasting text, it is possible that part of the text is still pasted but part of it is not. For example, if there is a maximum length set then only the first part of the text is pasted and the rest is dropped. In this case it should still emit inputRejected() as not all of the input was accepted. This amends c901cdadc0a6ec65eddfe4f181274e56567f9973. Change-Id: If7906767be27e88ed9914c50bf0427833de5b8fa Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/widgets/qlineedit.cpp5
-rw-r--r--src/widgets/widgets/qwidgetlinecontrol.cpp4
2 files changed, 7 insertions, 2 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 43aa10bdb6..bb1bf64ba0 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -1681,6 +1681,11 @@ void QLineEdit::mouseDoubleClickEvent(QMouseEvent* e)
results in a validator's validate() call to return Invalid.
Another case is when trying to enter in more characters beyond the
maximum length of the line edit.
+
+ Note: This signal will still be emitted in a case where part of
+ the text is accepted but not all of it is. For example, if there
+ is a maximum length set and the clipboard text is longer than the
+ maximum length when it is pasted.
*/
/*!
diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp
index 670735df3b..b5af8e36aa 100644
--- a/src/widgets/widgets/qwidgetlinecontrol.cpp
+++ b/src/widgets/widgets/qwidgetlinecontrol.cpp
@@ -872,9 +872,9 @@ void QWidgetLineControl::internalInsert(const QString &s)
for (int i = 0; i < (int) s.left(remaining).length(); ++i)
addCommand(Command(Insert, m_cursor++, s.at(i), -1, -1));
m_textDirty = true;
- } else {
- emit inputRejected();
}
+ if (s.length() > remaining)
+ emit inputRejected();
}
}