diff options
Diffstat (limited to 'src/quick/items/qquicktableview.cpp')
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index bf47d43c8f..ecd302a761 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -4768,6 +4768,20 @@ void QQuickTableView::keyPressEvent(QKeyEvent *e) const QModelIndex currentIndex = d->selectionModel->currentIndex(); const QPoint currentCell = cellAtIndex(currentIndex); + if (!d->cellIsValid(currentCell)) { + switch (e->key()) { + case Qt::Key_Up: + case Qt::Key_Down: + case Qt::Key_Left: + case Qt::Key_Right: + // Special case: the current index doesn't map to a cell in the view (perhaps + // because it isn't set yet). In that case, we set it to be the top-left cell. + const QModelIndex topLeftIndex = modelIndex(leftColumn(), topRow()); + d->selectionModel->setCurrentIndex(topLeftIndex, QItemSelectionModel::NoUpdate); + } + return; + } + auto beginMoveCurrentIndex = [=](){ if (!select) { d->clearSelection(); |