From d22bafe3559afef1dcab1c9076f82ac224d012b6 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 23 Nov 2021 15:32:55 +0100 Subject: QTableView: correctly toggle column selection when scrolled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to check whether the horizontal header's selection includes the index for the row at the top, rather than for row 0, as the index we check is based on the scrolled position of the header, so would never be included in the top row when the view is scrolled. This is correctly done in selectRow already. Add a test case that simulates selection of rows and columns by clicking on the header. Fixes: QTBUG-98444 Pick-to: 6.2 Change-Id: I2fa1b32bf75dc96225b40145b713bf7e2ffc29dd Reviewed-by: Tor Arne Vestbø --- src/widgets/itemviews/qtableview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets/itemviews/qtableview.cpp') diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 62bc9d1ff1..d1b82c2511 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -3467,7 +3467,7 @@ void QTableViewPrivate::selectColumn(int column, bool anchor) if (q->selectionMode() != QTableView::SingleSelection && command.testFlag(QItemSelectionModel::Toggle)) { if (anchor) - ctrlDragSelectionFlag = horizontalHeader->selectionModel()->selectedColumns().contains(index) + ctrlDragSelectionFlag = horizontalHeader->selectionModel()->selectedColumns(row).contains(index) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select; command &= ~QItemSelectionModel::Toggle; command |= ctrlDragSelectionFlag; -- cgit v1.2.3