diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2021-04-21 21:29:19 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-07-12 08:19:16 +0000 |
commit | e8b3d35a18e7e4cf6543868d89d6060c90314f39 (patch) | |
tree | 50f1cf00c959fe1b40111c5183bdbf950bf3fe22 /src/widgets/itemviews | |
parent | e71a5d5cc3c0337e7dbd5d571ecee5668baf8b63 (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
Pick-to: 6.1 6.2
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/itemviews')
-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 384a34d5a1..d1793a3049 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -3410,7 +3410,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)) { @@ -3423,6 +3423,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())) { @@ -3449,7 +3450,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)) { @@ -3462,6 +3463,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; |