From febe263d16c177cf0a8d6fb96bdf0c12acc62248 Mon Sep 17 00:00:00 2001 From: dengzhongyuan Date: Wed, 22 Jan 2025 15:49:50 +0800 Subject: [PATCH] fix: clear desktop selection when collection view gets focus - add selection clearing in CanvasView's focusOutEvent - add selection clearing in CollectionView's focusOutEvent log: When switching focus between desktop and collection view, clear previous selection to avoid showing multiple highlighted items across different views. bug: https://pms.uniontech.com/bug-view-300259.htm --- src/plugins/desktop/ddplugin-canvas/view/canvasview.cpp | 4 ++++ .../desktop/ddplugin-organizer/view/collectionview.cpp | 8 ++++++++ .../desktop/ddplugin-organizer/view/collectionview.h | 1 + 3 files changed, 13 insertions(+) diff --git a/src/plugins/desktop/ddplugin-canvas/view/canvasview.cpp b/src/plugins/desktop/ddplugin-canvas/view/canvasview.cpp index 4107fcda51..df535db83a 100644 --- a/src/plugins/desktop/ddplugin-canvas/view/canvasview.cpp +++ b/src/plugins/desktop/ddplugin-canvas/view/canvasview.cpp @@ -474,6 +474,10 @@ void CanvasView::focusOutEvent(QFocusEvent *event) { d->dodgeOper->stopDelayDodge(); d->dodgeOper->updatePrepareDodgeValue(event); + + if (selectionModel()) + selectionModel()->clearSelection(); + QAbstractItemView::focusOutEvent(event); } diff --git a/src/plugins/desktop/ddplugin-organizer/view/collectionview.cpp b/src/plugins/desktop/ddplugin-organizer/view/collectionview.cpp index 48c03c11a5..296847b107 100644 --- a/src/plugins/desktop/ddplugin-organizer/view/collectionview.cpp +++ b/src/plugins/desktop/ddplugin-organizer/view/collectionview.cpp @@ -421,6 +421,14 @@ QPixmap CollectionViewPrivate::polymerizePixmap(QModelIndexList indexs) const return pixmap; } +void CollectionView::focusOutEvent(QFocusEvent *event) +{ + if (selectionModel()) + selectionModel()->clearSelection(); + + QAbstractItemView::focusOutEvent(event); +} + bool CollectionViewPrivate::checkClientMimeData(QDragEnterEvent *event) const { if (DFileDragClient::checkMimeData(event->mimeData())) { diff --git a/src/plugins/desktop/ddplugin-organizer/view/collectionview.h b/src/plugins/desktop/ddplugin-organizer/view/collectionview.h index c05dc63d2a..bd65346df2 100644 --- a/src/plugins/desktop/ddplugin-organizer/view/collectionview.h +++ b/src/plugins/desktop/ddplugin-organizer/view/collectionview.h @@ -96,6 +96,7 @@ protected Q_SLOTS: void dragLeaveEvent(QDragLeaveEvent *event) override; void dropEvent(QDropEvent *event) override; void focusInEvent(QFocusEvent *event) override; + void focusOutEvent(QFocusEvent *event) override; void scrollContentsBy(int dx, int dy) override;