QTableView: fix dropping between items when precisely on the cell border

There's a one-pixel horizontal line between two cells where
indexAt(pos) returns a valid index and visualRect(index) doesn't contain
pos, because of the 1 pixel cell border.
So this code (whose origin predates public git history) would turn the
valid index into the root index, leading to an unexpected append instead
of insert.

The only other case I could find where this condition happened was when
dropping onto the branches of a QTreeView, but even there it seems much
more expected to drop on the item (or between items) than on the viewport
(which often means append at the very bottom, far from the drop area).

Change-Id: Ia7c884d3fc925a7536ea3ab75851366c531d8438
Pick-to: 6.8
Fixes: QTBUG-130045
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
This commit is contained in:
David Faure 2024-10-14 19:50:31 +02:00
parent 7370048940
commit f9336a05bc

View File

@ -2207,7 +2207,7 @@ bool QAbstractItemViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *drop
// rootIndex() (i.e. the viewport) might be a valid index
if (viewport->rect().contains(event->position().toPoint())) {
index = q->indexAt(event->position().toPoint());
if (!index.isValid() || !q->visualRect(index).contains(event->position().toPoint()))
if (!index.isValid())
index = root;
}