From d6551fe125209f11445936a90ce2a4207a183917 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 27 Aug 2019 10:08:28 +0200 Subject: [PATCH] QTree/TableView: Don't emit clicked when releasing after double click MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If an item is double clicked, then without this fix, the views emit the clicked() signal when the mousebutton is released after the double click event. This is unexpected and wrong. QAbstractItemView keeps track of the item the mouse was pressed on, to verify that the release occurred on the same item before emitting clicked, and to make sure we have a valid pressed item before initiating drag'n'drop. By resetting d->pressedItem when a double click has been handled, we can prevent the emission of a clicked signal in the next release event. [ChangeLog][QtWidgets][QTreeView] Don't emit clicked signal after a doubleClicked signal. Fixes: QTBUG-77771 Change-Id: I05988e9e2222157f4216cebc40c22507e8d83b82 Reviewed-by: André de la Rocha Reviewed-by: Jesus Fernandez --- src/widgets/itemviews/qabstractitemview.cpp | 1 + src/widgets/itemviews/qtreeview.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 2ed5df46b8..089f398e71 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -1966,6 +1966,7 @@ void QAbstractItemView::mouseDoubleClickEvent(QMouseEvent *event) if ((event->button() == Qt::LeftButton) && !edit(persistent, DoubleClicked, event) && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this)) emit activated(persistent); + d->pressedIndex = QModelIndex(); } #if QT_CONFIG(draganddrop) diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 823be1ca08..413cc2a9cd 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -1943,6 +1943,7 @@ void QTreeView::mouseDoubleClickEvent(QMouseEvent *event) if (!style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this)) emit activated(persistent); + d->pressedIndex = QModelIndex(); d->executePostedLayout(); // we need to make sure viewItems is updated if (d->itemsExpandable && d->expandsOnDoubleClick