From b85d09cd9c488582fff83e7115e5c7dd5c739df0 Mon Sep 17 00:00:00 2001 From: Ivan Leontiev Date: Fri, 15 Jan 2016 02:17:40 +0300 Subject: [PATCH] Fix misbehavior when you double click after a single click on a tree item This issue appeared as a side effect since the commit bcaa9e4a37b732f91a36539e313937537be7aba2, which adds dropdown animation to the library/internet view. Reproduce: Single/double click on a song item in library/internet view then all double clicks on this item will be ignored, until you single click on it once again. The reason of this behavior in that the "setExpanded" method call from the "ItemClicked" slot makes the invocation of the "mouseDoubleClickEvent" method in the context where the view is in the "QAbstractTreeView::AnimatingState" which makes impossible to emit "doubleClicked" signal, because it just returns immediatelly (see http://code.qt.io/cgit/qt/qt.git/tree/src/gui/itemviews/qtreeview.cpp#n1849). To get rid of this behavior we emit "doubleClicked" signal ourselves. --- src/widgets/autoexpandingtreeview.cpp | 14 ++++++++++++++ src/widgets/autoexpandingtreeview.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/widgets/autoexpandingtreeview.cpp b/src/widgets/autoexpandingtreeview.cpp index d5cf2152e..d5aa1bb82 100644 --- a/src/widgets/autoexpandingtreeview.cpp +++ b/src/widgets/autoexpandingtreeview.cpp @@ -113,6 +113,20 @@ void AutoExpandingTreeView::mousePressEvent(QMouseEvent* event) { } } +void AutoExpandingTreeView::mouseDoubleClickEvent(QMouseEvent* event) { + State p_state = state(); + QModelIndex index = indexAt(event->pos()); + + QTreeView::mouseDoubleClickEvent(event); + + // If the p_state was the "AnimatingState", then the base class's + // "mouseDoubleClickEvent" method just did nothing, hence the + // "doubleClicked" signal is not emitted. So let's do it ourselves. + if (index.isValid() && p_state == AnimatingState) { + emit doubleClicked(index); + } +} + void AutoExpandingTreeView::keyPressEvent(QKeyEvent* e) { switch (e->key()) { case Qt::Key_Enter: diff --git a/src/widgets/autoexpandingtreeview.h b/src/widgets/autoexpandingtreeview.h index 3c5de36d2..c38e9df03 100644 --- a/src/widgets/autoexpandingtreeview.h +++ b/src/widgets/autoexpandingtreeview.h @@ -47,6 +47,7 @@ signals: // QWidget void mousePressEvent(QMouseEvent* event); + void mouseDoubleClickEvent(QMouseEvent* event); void keyPressEvent(QKeyEvent* event); virtual bool CanRecursivelyExpand(const QModelIndex& index) const {