diff options
-rw-r--r-- | src/gui/util/qcompleter.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qcompleter/tst_qcompleter.cpp | 40 |
2 files changed, 42 insertions, 2 deletions
diff --git a/src/gui/util/qcompleter.cpp b/src/gui/util/qcompleter.cpp index f4adcea..d68e309 100644 --- a/src/gui/util/qcompleter.cpp +++ b/src/gui/util/qcompleter.cpp @@ -1182,7 +1182,7 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e) case Qt::Key_Up: if (!curIndex.isValid()) { int rowCount = d->proxy->rowCount(); - QModelIndex lastIndex = d->proxy->index(rowCount - 1, 0); + QModelIndex lastIndex = d->proxy->index(rowCount - 1, d->column); d->setCurrentIndex(lastIndex); return true; } else if (curIndex.row() == 0) { @@ -1194,7 +1194,7 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e) case Qt::Key_Down: if (!curIndex.isValid()) { - QModelIndex firstIndex = d->proxy->index(0, 0); + QModelIndex firstIndex = d->proxy->index(0, d->column); d->setCurrentIndex(firstIndex); return true; } else if (curIndex.row() == d->proxy->rowCount() - 1) { diff --git a/tests/auto/qcompleter/tst_qcompleter.cpp b/tests/auto/qcompleter/tst_qcompleter.cpp index baea419..bbc01cc 100644 --- a/tests/auto/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/qcompleter/tst_qcompleter.cpp @@ -146,6 +146,8 @@ private slots: void task253125_lineEditCompletion_data(); void task253125_lineEditCompletion(); + void task247560_keyboardNavigation(); + private: void filter(); void testRowCount(); @@ -1230,5 +1232,43 @@ void tst_QCompleter::task253125_lineEditCompletion() QCOMPARE(edit.text(), QString("iota")); } +void tst_QCompleter::task247560_keyboardNavigation() +{ + QStandardItemModel model; + + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + model.setItem(i, j, new QStandardItem(QString("row %1 column %2").arg(i).arg(j))); + } + } + + + QCompleter completer(&model); + completer.setCompletionColumn(1); + + QLineEdit edit; + edit.setCompleter(&completer); + edit.show(); + edit.setFocus(); + + QTest::qWait(100); + + QTest::keyClick(&edit, 'r'); + QTest::keyClick(edit.completer()->popup(), Qt::Key_Down); + QTest::keyClick(edit.completer()->popup(), Qt::Key_Down); + QTest::keyClick(edit.completer()->popup(), Qt::Key_Enter); + + QCOMPARE(edit.text(), QString("row 1 column 1")); + + edit.clear(); + + QTest::keyClick(&edit, 'r'); + QTest::keyClick(edit.completer()->popup(), Qt::Key_Up); + QTest::keyClick(edit.completer()->popup(), Qt::Key_Up); + QTest::keyClick(edit.completer()->popup(), Qt::Key_Enter); + + QCOMPARE(edit.text(), QString("row 3 column 1")); +} + QTEST_MAIN(tst_QCompleter) #include "tst_qcompleter.moc" |