diff options
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r-- | src/widgets/widgets/qlineedit.cpp | 10 | ||||
-rw-r--r-- | src/widgets/widgets/qlineedit.h | 1 | ||||
-rw-r--r-- | src/widgets/widgets/qlineedit_p.cpp | 1 | ||||
-rw-r--r-- | src/widgets/widgets/qwidgetlinecontrol.cpp | 8 | ||||
-rw-r--r-- | src/widgets/widgets/qwidgetlinecontrol_p.h | 1 |
5 files changed, 21 insertions, 0 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 9e70b54601..43aa10bdb6 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -1674,6 +1674,16 @@ void QLineEdit::mouseDoubleClickEvent(QMouseEvent* e) */ /*! + \fn void QLineEdit::inputRejected() + + This signal is emitted when the user presses a key that is not + considered to be acceptable input. For example, if a key press + 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. +*/ + +/*! Converts the given key press \a event into a line edit action. If Return or Enter is pressed and the current text is valid (or diff --git a/src/widgets/widgets/qlineedit.h b/src/widgets/widgets/qlineedit.h index 099bf4bb18..b3be97e9b7 100644 --- a/src/widgets/widgets/qlineedit.h +++ b/src/widgets/widgets/qlineedit.h @@ -207,6 +207,7 @@ Q_SIGNALS: void returnPressed(); void editingFinished(); void selectionChanged(); + void inputRejected(); protected: void mousePressEvent(QMouseEvent *) override; diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index acf49cda72..bfb92468be 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -214,6 +214,7 @@ void QLineEditPrivate::init(const QString& txt) QObject::connect(control, SIGNAL(updateNeeded(QRect)), q, SLOT(_q_updateNeeded(QRect))); + QObject::connect(control, SIGNAL(inputRejected()), q, SIGNAL(inputRejected())); QStyleOptionFrame opt; q->initStyleOption(&opt); 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(); } } } diff --git a/src/widgets/widgets/qwidgetlinecontrol_p.h b/src/widgets/widgets/qwidgetlinecontrol_p.h index ca70e2c02f..3e33bc0605 100644 --- a/src/widgets/widgets/qwidgetlinecontrol_p.h +++ b/src/widgets/widgets/qwidgetlinecontrol_p.h @@ -545,6 +545,7 @@ Q_SIGNALS: void accepted(); void editingFinished(); void updateNeeded(const QRect &); + void inputRejected(); #ifdef QT_KEYPAD_NAVIGATION void editFocusChange(bool); |