From f78842abe429dc9b42fd15dc8e9e842ab72dcf2b Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 17 Apr 2013 09:31:49 +0200 Subject: Ensure the QLineEdit::returnPressed() signal is still emitted The signal needs to be emitted directly as the event is not passed to the QLineEdit if the QSpinBox gets the Key_Return. Since this signal may be relied upon then we ensure it is emitted directly. Change-Id: I17cdec62c9f995bacfd7d3cc66d6324f26c84c67 Reviewed-by: Stephen Kelly --- src/widgets/widgets/qabstractspinbox.cpp | 1 + tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index 765dcb8981..288375fe28 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -990,6 +990,7 @@ void QAbstractSpinBox::keyPressEvent(QKeyEvent *event) selectAll(); event->ignore(); emit editingFinished(); + emit d->edit->returnPressed(); return; #ifdef QT_KEYPAD_NAVIGATION diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index 89b7bc6790..a64b34c56a 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -138,7 +138,7 @@ private slots: void integerOverflow(); void taskQTBUG_5008_textFromValueAndValidate(); - + void lineEditReturnPressed(); public slots: void valueChangedHelper(const QString &); void valueChangedHelper(int); @@ -1044,5 +1044,14 @@ void tst_QSpinBox::integerOverflow() QCOMPARE(sb.value(), INT_MIN); } +void tst_QSpinBox::lineEditReturnPressed() +{ + SpinBox spinBox; + QSignalSpy spyCurrentChanged(spinBox.lineEdit(), SIGNAL(returnPressed())); + spinBox.show(); + QTest::keyClick(&spinBox, Qt::Key_Return); + QCOMPARE(spyCurrentChanged.count(), 1); +} + QTEST_MAIN(tst_QSpinBox) #include "tst_qspinbox.moc" -- cgit v1.2.3