From 52c908fdb50e6f7716fd34622b73cd135aff5c1e Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 9 Aug 2024 18:34:11 +0200 Subject: [PATCH] QAbstractItemView: implement full-row drop indicator When the selection behavior is SelectRows, we're dragging full rows, so it was very weird that the drop indicator was showing a single column. Instead, expand the drop indicator over all columns. This is typically for QTreeView but it also works for a QTableView where a single row represents a single underlying object (otherwise, why use SelectRows?). Since we're testing the selection behavior of the drop side, not the drag side, only do this when inserting rows, or (for OnItem) when they're the same widget. There's a use case for dropping single properties (from a different widget) onto specific columns of full-row objects (there's also a use case for overwriting the whole object but we can't know which one it will be...). Fixes: QTBUG-1656 Change-Id: Idde0f4f8592970339f19dcc11ba667cf12677438 Reviewed-by: Christian Ehrlicher Reviewed-by: Volker Hilsheimer (cherry picked from commit a818326985295ba1cf1b31043b24e9f089b1d834) --- src/widgets/itemviews/qabstractitemview.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index f5698b7dcbb..d7f25295d1a 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -2074,6 +2074,13 @@ void QAbstractItemView::dragMoveEvent(QDragMoveEvent *event) if (index.isValid() && d->showDropIndicator) { QRect rect = visualRect(index); d->dropIndicatorPosition = d->position(event->position().toPoint(), rect, index); + if (d->selectionBehavior == QAbstractItemView::SelectRows + && d->dropIndicatorPosition != OnViewport + && (d->dropIndicatorPosition != OnItem || event->source() == this)) { + if (index.column() > 0) + rect = visualRect(index.siblingAtColumn(0)); + rect.setWidth(viewport()->width() - 1 - rect.x()); + } switch (d->dropIndicatorPosition) { case AboveItem: if (d->isIndexDropEnabled(index.parent())) {