Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.5.1
-
None
-
Windows 7, 64 bits, Microsoft Visual Studio 2008 SP1.
Description
Let's say we have a simplest model with two rows and three columns with fixed data. As in items-views tutorial. Pressing on a vertical header on any row selects all the row.
But if hide first column and swap second and third, than pressing on the vertical header doesn't select a row but only one cell. Please see attached screenshots.
It looks like the problem is caused by QTableViewPrivate::selectRow implementation. It tries to get visual spaces for logical but not visual indexes. The next patch fixes the problem for me. Hope it can help.
Index: qtbase/src/widgets/itemviews/qtableview.cpp =================================================================== --- qtbase/src/widgets/itemviews/qtableview.cpp (revision 2) +++ qtbase/src/widgets/itemviews/qtableview.cpp (revision 4) @@ -3252,14 +3252,17 @@ command |= QItemSelectionModel::Current; } - QModelIndex tl = model->index(qMin(rowSectionAnchor, row), logicalColumn(0), root); - QModelIndex br = model->index(qMax(rowSectionAnchor, row), logicalColumn(model->columnCount(root) - 1), root); - if ((verticalHeader->sectionsMoved() && tl.row() != br.row()) - || horizontalHeader->sectionsMoved()) { - q->setSelection(q->visualRect(tl)|q->visualRect(br), command); - } else { - selectionModel->select(QItemSelection(tl, br), command); - } + //QModelIndex tl = model->index(qMin(rowSectionAnchor, row), logicalColumn(0), root); + //QModelIndex br = model->index(qMax(rowSectionAnchor, row), logicalColumn(model->columnCount(root) - 1), root); + //if ((verticalHeader->sectionsMoved() && tl.row() != br.row()) + // || horizontalHeader->sectionsMoved()) { + // q->setSelection(q->visualRect(tl)|q->visualRect(br), command); + //} else { + // selectionModel->select(QItemSelection(tl, br), command); + //} + QModelIndex upper = model->index(qMin(rowSectionAnchor, row), column, root); + QModelIndex lower = model->index(qMax(rowSectionAnchor, row), column, root); + selectionModel->select(QItemSelection(upper, lower), command|QItemSelectionModel::Rows); } }
Attachments
Issue Links
- is duplicated by
-
QTBUG-52742 QTableView selectRow didn't work when column 0 is hidden and horizontal header moved.
- Closed
- relates to
-
QTBUG-50149 [REG: 4->5] Row selection with hidden columns is broken after QHeaderView::moveSection
- Closed