From e02293a76d21e7077f1952d4ed8af6c6d1970190 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 30 Sep 2019 08:26:36 +0200 Subject: Always update the pressed position when pressing on an item If there is an item already selected then the pressed position needs to be updated regardless when selecting a new one even if it is not made current as this will be used to determine the drag distance. Otherwise it will start a drag within one pixel of moving due to the fact it is doing it relative to the first item to be pressed rather than the last. Fixes: QTBUG-78797 Change-Id: I853041b278b2e92ccf20660f7ced945fef72527a Reviewed-by: Samuel Gaist Reviewed-by: Christian Ehrlicher --- src/widgets/itemviews/qabstractitemview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets/itemviews') diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index cb99214d4e..7d5e014dd5 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -1775,8 +1775,8 @@ void QAbstractItemView::mousePressEvent(QMouseEvent *event) QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); d->noSelectionOnMousePress = command == QItemSelectionModel::NoUpdate || !index.isValid(); QPoint offset = d->offset(); + d->pressedPosition = pos + offset; if ((command & QItemSelectionModel::Current) == 0) { - d->pressedPosition = pos + offset; d->currentSelectionStartIndex = index; } else if (!d->currentSelectionStartIndex.isValid()) -- cgit v1.2.3 From 5aa13ea144cff4dbadf12c08b7aa49646347e186 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 12 Sep 2019 15:22:24 +0200 Subject: QTreeWidget: Don't assume the selected indexes include the first column If the first column is hidden in a QTreeWidget then when doing a drag then the selected indexes will not include any that have a column of 0. Therefore it has to account for this use std::unique to ensure that there is only one instance of the selected items represented by the selected indexes. Fixes: QTBUG-35511 Change-Id: I39dff596959f30db7378ff946735ee2866778524 Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qtreewidget.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/widgets/itemviews') diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index d2dc91b18c..be7ddd8b30 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -748,11 +748,14 @@ QMimeData *QTreeModel::internalMimeData() const QMimeData *QTreeModel::mimeData(const QModelIndexList &indexes) const { - QList items; - for (const auto &index : indexes) { - if (index.column() == 0) // only one item per row - items << item(index); - } + QList items; + std::transform(indexes.begin(), indexes.end(), std::back_inserter(items), + [this](const QModelIndex &idx) -> QTreeWidgetItem * { return item(idx); }); + + // Ensure we only have one item as an item may have more than + // one index selected if there is more than one column + std::sort(items.begin(), items.end()); + items.erase(std::unique(items.begin(), items.end()), items.end()); // cachedIndexes is a little hack to avoid copying from QModelIndexList to // QList and back again in the view -- cgit v1.2.3