From 3cf0237f048b724178fcd481a9b814ffcc012c1b Mon Sep 17 00:00:00 2001 From: HinGwenWoong Date: Sun, 20 Feb 2022 17:46:10 +0800 Subject: [PATCH] Select box wil select key in key list at the same time --- PPOCRLabel/PPOCRLabel.py | 5 ++++- PPOCRLabel/libs/unique_label_qlist_widget.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/PPOCRLabel/PPOCRLabel.py b/PPOCRLabel/PPOCRLabel.py index 105989c7..3eb38c7e 100644 --- a/PPOCRLabel/PPOCRLabel.py +++ b/PPOCRLabel/PPOCRLabel.py @@ -465,7 +465,7 @@ class MainWindow(QMainWindow): 'Ctrl+Z', "undo", getStr("undo"), enabled=False) change_cls = action(getStr("keyChange"), self.change_box_key, - 'Ctrl+B', "undo", getStr("keyChange"), enabled=False) + 'Ctrl+B', "edit", getStr("keyChange"), enabled=False) lock = action(getStr("lockBox"), self.lockSelectedShape, None, "lock", getStr("lockBoxDetail"), @@ -980,6 +980,9 @@ class MainWindow(QMainWindow): self.labelList.scrollToItem(self.currentItem()) # QAbstractItemView.EnsureVisible self.BoxList.scrollToItem(self.currentBox()) + if len(self.canvas.selectedShapes) == 1 and self.keyList.count() > 0: + selected_key_item_row = self.keyList.findItemsByLabel(self.canvas.selectedShapes[0].key_cls, get_row=True) + self.keyList.setCurrentRow(selected_key_item_row) self._noSelectionSlot = False n_selected = len(selected_shapes) diff --git a/PPOCRLabel/libs/unique_label_qlist_widget.py b/PPOCRLabel/libs/unique_label_qlist_widget.py index 785647f8..f1eff7a1 100644 --- a/PPOCRLabel/libs/unique_label_qlist_widget.py +++ b/PPOCRLabel/libs/unique_label_qlist_widget.py @@ -17,12 +17,14 @@ class UniqueLabelQListWidget(EscapableQListWidget): if not self.indexAt(event.pos()).isValid(): self.clearSelection() - def findItemsByLabel(self, label): + def findItemsByLabel(self, label, get_row=False): items = [] for row in range(self.count()): item = self.item(row) if item.data(Qt.UserRole) == label: items.append(item) + if get_row: + return row return items def createItemFromLabel(self, label): -- GitLab