diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2021-04-21 21:29:19 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-07-14 10:42:44 +0000 |
commit | 39817d0f3b20822cee91c55e54aae4d6289b105d (patch) | |
tree | f34b79c6db71eab5d24f9619a1b51da8beb3d857 /src | |
parent | e8d39c670ee9ee5f097fcab27c8070103a3c4b68 (diff) |
QTableView: fix selection with rows and cells in ExtendedSelection mode
QTableView stored the current row/column selection start in an own
variable instead using currentSelectionStartIndex. This leads to an
inconsistent behavior when the selection is done with a click on the
header and then in a cell (and the other way round)
Fixes: QTBUG-92561
Change-Id: I4c8bda3a938de451b6eff2819141e86a6870fbef
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit e8b3d35a18e7e4cf6543868d89d6060c90314f39)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/itemviews/qtableview.cpp | 6 | ||||
-rw-r--r-- | src/widgets/itemviews/qtableview_p.h | 3 |
2 files changed, 4 insertions, 5 deletions
diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 05d8807e10..1c31711a52 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -3388,7 +3388,7 @@ void QTableViewPrivate::selectRow(int row, bool anchor) selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); if ((anchor && !(command & QItemSelectionModel::Current)) || (q->selectionMode() == QTableView::SingleSelection)) - rowSectionAnchor = row; + currentSelectionStartIndex = model->index(row, column, root); if (q->selectionMode() != QTableView::SingleSelection && command.testFlag(QItemSelectionModel::Toggle)) { @@ -3401,6 +3401,7 @@ void QTableViewPrivate::selectRow(int row, bool anchor) command |= QItemSelectionModel::Current; } + const auto rowSectionAnchor = currentSelectionStartIndex.row(); QModelIndex upper = model->index(qMin(rowSectionAnchor, row), column, root); QModelIndex lower = model->index(qMax(rowSectionAnchor, row), column, root); if ((verticalHeader->sectionsMoved() && upper.row() != lower.row())) { @@ -3427,7 +3428,7 @@ void QTableViewPrivate::selectColumn(int column, bool anchor) selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); if ((anchor && !(command & QItemSelectionModel::Current)) || (q->selectionMode() == QTableView::SingleSelection)) - columnSectionAnchor = column; + currentSelectionStartIndex = model->index(row, column, root); if (q->selectionMode() != QTableView::SingleSelection && command.testFlag(QItemSelectionModel::Toggle)) { @@ -3440,6 +3441,7 @@ void QTableViewPrivate::selectColumn(int column, bool anchor) command |= QItemSelectionModel::Current; } + const auto columnSectionAnchor = currentSelectionStartIndex.column(); QModelIndex left = model->index(row, qMin(columnSectionAnchor, column), root); QModelIndex right = model->index(row, qMax(columnSectionAnchor, column), root); if ((horizontalHeader->sectionsMoved() && left.column() != right.column())) { diff --git a/src/widgets/itemviews/qtableview_p.h b/src/widgets/itemviews/qtableview_p.h index 2b110f18a0..23095c0087 100644 --- a/src/widgets/itemviews/qtableview_p.h +++ b/src/widgets/itemviews/qtableview_p.h @@ -136,7 +136,6 @@ class QTableViewPrivate : public QAbstractItemViewPrivate public: QTableViewPrivate() : showGrid(true), gridStyle(Qt::SolidLine), - rowSectionAnchor(-1), columnSectionAnchor(-1), columnResizeTimerID(0), rowResizeTimerID(0), horizontalHeader(nullptr), verticalHeader(nullptr), sortingEnabled(false), geometryRecursionBlock(false), @@ -186,8 +185,6 @@ public: bool showGrid; Qt::PenStyle gridStyle; - int rowSectionAnchor; - int columnSectionAnchor; int columnResizeTimerID; int rowResizeTimerID; QList<int> columnsToUpdate; |