From a1c985c10bf2212e911777568c6e344456293a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Thu, 12 Oct 2017 10:58:06 +0200 Subject: QAbstractItemView: Make it easier to drop above and below items Before this patch a very accurate drop position below or above an index was needed. Therefore it was not that easy to do. This patch increases the above/below area to be about 18% of the item (still leaving the most space for the item). An average user will likely be 2-3x faster with dropping below or above (while not losing much when dropping on items). [ChangeLog][QtWidgets][ItemViews] Made it easier to drop above and below items. Change-Id: I47f0f80c76878c17ebf3f93d0a0cc82755971c2a Reviewed-by: Andy Shaw Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qabstractitemview.cpp | 2 +- tests/manual/widgets/itemviews/qtreewidget/main.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 15e6b0eb99..23e727e670 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -2194,7 +2194,7 @@ QAbstractItemViewPrivate::position(const QPoint &pos, const QRect &rect, const Q { QAbstractItemView::DropIndicatorPosition r = QAbstractItemView::OnViewport; if (!overwrite) { - const int margin = 2; + const int margin = qBound(2, qRound(qreal(rect.height()) / 5.5), 12); if (pos.y() - rect.top() < margin) { r = QAbstractItemView::AboveItem; } else if (rect.bottom() - pos.y() < margin) { diff --git a/tests/manual/widgets/itemviews/qtreewidget/main.cpp b/tests/manual/widgets/itemviews/qtreewidget/main.cpp index 5d129101fd..fb72c404a5 100644 --- a/tests/manual/widgets/itemviews/qtreewidget/main.cpp +++ b/tests/manual/widgets/itemviews/qtreewidget/main.cpp @@ -95,6 +95,18 @@ public: item5sl.append("Approver"); /* QTreeWidgetItem *item4 =*/ new QTreeWidgetItem(item4, item5sl); + treeWidget->setDragEnabled(true); + treeWidget->viewport()->setAcceptDrops(true); + treeWidget->setDragDropMode(QAbstractItemView::InternalMove); + + for (int u = 0; u < 12; ++u) { + const QString username = QString("Anonymous User %1").arg(u + 1); + QStringList info; + info << username << username << QString::number(u + 1) << QStringLiteral("Test user"); + new QTreeWidgetItem(item4, info); + } + + treeWidget->expandAll(); treeWidget->setColumnCount(item2sl.size()); QStringList itemInfo("First Name"); itemInfo.append("Last Name"); @@ -133,6 +145,7 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); ExampleDlg d; + d.resize(d.sizeHint() * 3); d.show(); app.exec(); } -- cgit v1.2.3