summaryrefslogtreecommitdiffstats
path: root/tests/auto/qcombobox
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-10-30 08:55:20 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-10-30 12:42:08 (GMT)
commitd025ebb1a8163cd1f03151927486cf62c5e77957 (patch)
tree0ccef8c9a9012ab63f20f100a824abb1516d9886 /tests/auto/qcombobox
parent85b7896a47f9bb622b394107769cb7c1121a6995 (diff)
downloadQt-d025ebb1a8163cd1f03151927486cf62c5e77957.zip
Qt-d025ebb1a8163cd1f03151927486cf62c5e77957.tar.gz
Qt-d025ebb1a8163cd1f03151927486cf62c5e77957.tar.bz2
Fixes regression in QComboBox with keypad navigation while mouse is over the popup
The problem is that is we move the selection with the keyboard in a way that causes the view to scroll, the current selection would jump. This happends since commit 9cb231d773db6deb that fixed the emission of the enter signal when the view is scrolled. We Therefor cannot use the enter signal. Catch manually the mouse move events to update the selection instead. Reviewed-by: Thierry
Diffstat (limited to 'tests/auto/qcombobox')
-rw-r--r--tests/auto/qcombobox/tst_qcombobox.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp
index 8acae7a..51a7ff8 100644
--- a/tests/auto/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/qcombobox/tst_qcombobox.cpp
@@ -153,6 +153,7 @@ private slots:
void task260974_menuItemRectangleForComboBoxPopup();
void removeItem();
void resetModel();
+ void keyBoardNavigationWithMouse();
protected slots:
void onEditTextChanged( const QString &newString );
@@ -2448,6 +2449,57 @@ void tst_QComboBox::resetModel()
}
+void tst_QComboBox::keyBoardNavigationWithMouse()
+{
+ QComboBox combo;
+ combo.setEditable(false);
+ for (int i = 0; i < 80; i++)
+ combo.addItem( QString::number(i));
+ combo.show();
+ QApplication::setActiveWindow(&combo);
+ QTest::qWaitForWindowShown(&combo);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&combo));
+
+ QCOMPARE(combo.currentText(), QLatin1String("0"));
+
+ combo.setFocus();
+ QTRY_VERIFY(combo.hasFocus());
+
+ QTest::keyClick(testWidget->lineEdit(), Qt::Key_Space);
+ QTest::qWait(30);
+ QTRY_VERIFY(combo.view());
+ QTRY_VERIFY(combo.view()->isVisible());
+ QTest::qWait(130);
+
+ QCOMPARE(combo.currentText(), QLatin1String("0"));
+
+ QCursor::setPos(combo.view()->mapToGlobal(combo.view()->rect().center()));
+ QTest::qWait(200);
+
+#define GET_SELECTION(SEL) \
+ QCOMPARE(combo.view()->selectionModel()->selection().count(), 1); \
+ QCOMPARE(combo.view()->selectionModel()->selection().indexes().count(), 1); \
+ SEL = combo.view()->selectionModel()->selection().indexes().first().row()
+
+ int selection;
+ GET_SELECTION(selection);
+
+ //since we moved the mouse is in the middle it should even be around 5;
+ QVERIFY(selection > 3);
+
+ static const int final = 40;
+ for (int i = selection + 1; i <= final; i++)
+ {
+ QTest::keyClick(combo.view(), Qt::Key_Down);
+ QTest::qWait(20);
+ GET_SELECTION(selection);
+ QCOMPARE(selection, i);
+ }
+
+ QTest::keyClick(combo.view(), Qt::Key_Enter);
+ QTRY_COMPARE(combo.currentText(), QString::number(final));
+}
+
QTEST_MAIN(tst_QComboBox)
#include "tst_qcombobox.moc"