From 399906b24e7a98f627418a87b39fa0c959352798 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 17 Aug 2010 08:34:16 +0000 Subject: Make enter/return skip to next (tab) widget. --- client/test/testlineedit.cc | 37 +++++++++++++++++++++++++++++++++++++ client/widgets/lineedit.cc | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'client') diff --git a/client/test/testlineedit.cc b/client/test/testlineedit.cc index 577e0da..e8c9e40 100644 --- a/client/test/testlineedit.cc +++ b/client/test/testlineedit.cc @@ -2,6 +2,9 @@ #include #include "util.h" #include "lineedit.h" +#include +#include +#include static QString xml = "\n"; @@ -40,6 +43,40 @@ private slots: QTest::keyClicks(le.qwidget(), "h"); QCOMPARE(spy.count(), 1); } + + void tabOut() + { + QDomDocument doc; doc.setContent(xml); + QDomElement e = doc.documentElement(); + QWidget main; + LineEdit le(e, createMacroWindow()); + le.qwidget()->setParent(&main); + QLineEdit qle(&main); + main.show(); + + QApplication::processEvents(); + + QTest::mouseClick(le.qwidget(), Qt::LeftButton); + QApplication::processEvents(); + QCOMPARE(QApplication::focusWidget(), le.qwidget()); + QTest::keyClick(le.qwidget(), Qt::Key_Enter); + QApplication::processEvents(); + QVERIFY(QApplication::focusWidget() != le.qwidget()); + + QTest::mouseClick(le.qwidget(), Qt::LeftButton); + QApplication::processEvents(); + QCOMPARE(QApplication::focusWidget(), le.qwidget()); + QTest::keyClick(le.qwidget(), Qt::Key_Return); + QApplication::processEvents(); + QVERIFY(QApplication::focusWidget() != le.qwidget()); + + QTest::mouseClick(le.qwidget(), Qt::LeftButton); + QApplication::processEvents(); + QCOMPARE(QApplication::focusWidget(), le.qwidget()); + QTest::keyClick(le.qwidget(), Qt::Key_Tab); + QApplication::processEvents(); + QVERIFY(QApplication::focusWidget() != le.qwidget()); + } }; QTEST_MAIN(TestLineEdit) diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc index 9fb5f09..a8ea600 100644 --- a/client/widgets/lineedit.cc +++ b/client/widgets/lineedit.cc @@ -103,7 +103,7 @@ bool LineEdit::eventFilter(QObject *, QEvent *event) if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) { QKeyEvent tabevent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); - QCoreApplication::sendEvent(this, &tabevent); + QCoreApplication::sendEvent(lineedit, &tabevent); } } return false; -- cgit v1.2.3