From 9ea51f22ad0f51e55afee97faec9ebd2befe8177 Mon Sep 17 00:00:00 2001 From: jixiaoxu Date: Wed, 8 Sep 2021 15:41:28 +0800 Subject: [PATCH] Fix multiple widget selection bug; --- frontend/view/result-view.cpp | 15 +++++++++++++++ frontend/view/result-view.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/frontend/view/result-view.cpp b/frontend/view/result-view.cpp index eac36f6..ef6144f 100644 --- a/frontend/view/result-view.cpp +++ b/frontend/view/result-view.cpp @@ -278,6 +278,21 @@ void ResultView::onMenuTriggered(QAction *action) } } +void ResultView::mousePressEvent(QMouseEvent *event) +{ + m_mousePressIndex = indexAt(event->pos()); + return QTreeView::mousePressEvent(event); +} + +void ResultView::mouseReleaseEvent(QMouseEvent *event) +{ + QModelIndex index = indexAt(event->pos()); + if (!index.isValid() or index != m_mousePressIndex) { + this->clearSelection(); + } + return QTreeView::mouseReleaseEvent(event); +} + void ResultView::initConnections() { connect(this, &ResultView::startSearch, [ = ](const QString &keyword) { diff --git a/frontend/view/result-view.h b/frontend/view/result-view.h index 15dc698..1fc1f36 100644 --- a/frontend/view/result-view.h +++ b/frontend/view/result-view.h @@ -33,6 +33,10 @@ public Q_SLOTS: const bool &isExpanded(); void onMenuTriggered(QAction *); +protected: + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + private: void initConnections(); SearchResultModel * m_model = nullptr; @@ -40,6 +44,7 @@ private: bool m_is_selected = false; ResultViewDelegate * m_style_delegate = nullptr; int m_count = 0; + QModelIndex m_mousePressIndex; Q_SIGNALS: void startSearch(const QString &);