diff options
author | Andy Shaw <andy.shaw@qt.io> | 2018-05-30 20:58:24 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2018-06-01 21:34:03 +0000 |
commit | c901cdadc0a6ec65eddfe4f181274e56567f9973 (patch) | |
tree | 0cd722d395efc2b96a394ac862f1cda6ff61a9c3 /src/widgets/widgets/qwidgetlinecontrol.cpp | |
parent | e3e0a6d6d6c50dc21439f24728ee3614c5825d36 (diff) |
QLineEdit: Add an inputRejected() signal for when a key is not allowed
[ChangeLog][QtWidgets][QLineEdit] Added inputRejected() signal for when
a key press is not accepted by the QLineEdit. For instance, when an
invalid key is pressed for a validator set.
Task-number: QTBUG-57448
Change-Id: I39182a78b07b37c6da01905b8da4c57930e3454b
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/widgets/qwidgetlinecontrol.cpp')
-rw-r--r-- | src/widgets/widgets/qwidgetlinecontrol.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index ff00e26683..670735df3b 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -715,6 +715,8 @@ bool QWidgetLineControl::finishChange(int validateFromState, bool update, bool e return true; } m_cursor = cursorCopy; + } else { + emit inputRejected(); } } #endif @@ -762,6 +764,8 @@ void QWidgetLineControl::internalSetText(const QString &txt, int pos, bool edite if (m_maskData) { m_text = maskString(0, txt, true); m_text += clearString(m_text.length(), m_maxLength - m_text.length()); + if (edited && oldText == m_text) + emit inputRejected(); } else { m_text = txt.isEmpty() ? txt : txt.left(m_maxLength); } @@ -839,6 +843,8 @@ void QWidgetLineControl::internalInsert(const QString &s) addCommand(Command(SetSelection, m_cursor, 0, m_selstart, m_selend)); if (m_maskData) { QString ms = maskString(m_cursor, s); + if (ms.isEmpty() && !s.isEmpty()) + emit inputRejected(); #ifndef QT_NO_ACCESSIBILITY QAccessibleTextInsertEvent insertEvent(accessibleObject(), m_cursor, ms); QAccessible::updateAccessibility(&insertEvent); @@ -866,6 +872,8 @@ 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(); } } } |