QLineEdit: ignore key release events
Amends 55fe46fd58c73a7a22374694a1b45ec2a0e6fdc5. Before that change, key release events were ignored as the QLineEdit::event reimplementation continued to call QWidget::event, and as QLineEdit didn't override keyReleaseEvent, the default implementation in QWidget got called to ignore the event. Restore that behavior by explicitly calling the QWidget implementation after updating QLineEdit-specific states, and add a test case. Fixes: QTBUG-114654 Change-Id: Ic8aa35a1c915b446aece47aaf03ef5cf1884b936 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 8afe4faf298798783278f992d14fb78cecee9588) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
f10448ffaf
commit
1b5b090a5a
@ -1747,12 +1747,13 @@ void QLineEdit::keyPressEvent(QKeyEvent *event)
|
|||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
*/
|
*/
|
||||||
void QLineEdit::keyReleaseEvent(QKeyEvent *)
|
void QLineEdit::keyReleaseEvent(QKeyEvent *e)
|
||||||
{
|
{
|
||||||
Q_D(QLineEdit);
|
Q_D(QLineEdit);
|
||||||
if (!isReadOnly())
|
if (!isReadOnly())
|
||||||
d->handleSoftwareInputPanel();
|
d->handleSoftwareInputPanel();
|
||||||
d->control->updateCursorBlinking();
|
d->control->updateCursorBlinking();
|
||||||
|
QWidget::keyReleaseEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -292,6 +292,8 @@ private slots:
|
|||||||
void QTBUG_60319_setInputMaskCheckImSurroundingText();
|
void QTBUG_60319_setInputMaskCheckImSurroundingText();
|
||||||
void testQuickSelectionWithMouse();
|
void testQuickSelectionWithMouse();
|
||||||
void inputRejected();
|
void inputRejected();
|
||||||
|
void keyReleasePropagates();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void editingFinished();
|
void editingFinished();
|
||||||
|
|
||||||
@ -5143,5 +5145,43 @@ void tst_QLineEdit::inputRejected()
|
|||||||
QCOMPARE(spyInputRejected.size(), 2);
|
QCOMPARE(spyInputRejected.size(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QLineEdit::keyReleasePropagates()
|
||||||
|
{
|
||||||
|
struct Dialog : QWidget
|
||||||
|
{
|
||||||
|
QLineEdit *lineEdit;
|
||||||
|
int releasedKey = {};
|
||||||
|
|
||||||
|
Dialog()
|
||||||
|
{
|
||||||
|
lineEdit = new QLineEdit;
|
||||||
|
QHBoxLayout *hbox = new QHBoxLayout;
|
||||||
|
|
||||||
|
hbox->addWidget(lineEdit);
|
||||||
|
setLayout(hbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void keyReleaseEvent(QKeyEvent *e)
|
||||||
|
{
|
||||||
|
releasedKey = e->key();
|
||||||
|
}
|
||||||
|
} dialog;
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
QVERIFY(QTest::qWaitForWindowExposed(&dialog));
|
||||||
|
|
||||||
|
QTest::keyPress(dialog.lineEdit, Qt::Key_A);
|
||||||
|
QTest::keyRelease(dialog.lineEdit, Qt::Key_A);
|
||||||
|
|
||||||
|
QCOMPARE(dialog.releasedKey, Qt::Key_A);
|
||||||
|
|
||||||
|
QTest::keyPress(dialog.lineEdit, Qt::Key_Alt);
|
||||||
|
QTest::keyRelease(dialog.lineEdit, Qt::Key_Alt);
|
||||||
|
|
||||||
|
QCOMPARE(dialog.releasedKey, Qt::Key_Alt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(tst_QLineEdit)
|
QTEST_MAIN(tst_QLineEdit)
|
||||||
#include "tst_qlineedit.moc"
|
#include "tst_qlineedit.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user