From 5f9f17f9b43bd38b601d05303c13f299cdb39c50 Mon Sep 17 00:00:00 2001 From: wenliwyan Date: Thu, 14 Jun 2018 12:13:28 +0800 Subject: [PATCH] Add item single click slot in labelDialog.py (#312) * Add item single click slot in labelDialog.py In the original code, double clicking a list item will set the text property and automatically validate afterwards, with the label dialog window disappearing. In this revised version, double click behavior is unchanged, while single click is added. When single clicking a list item, it will only set text in the QLineEdit. Users can change the text by clicking other items before validating themselves by clicking yes. --- libs/labelDialog.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/labelDialog.py b/libs/labelDialog.py index a572f213..4df80545 100644 --- a/libs/labelDialog.py +++ b/libs/labelDialog.py @@ -40,7 +40,8 @@ class LabelDialog(QDialog): self.listWidget = QListWidget(self) for item in listItem: self.listWidget.addItem(item) - self.listWidget.itemDoubleClicked.connect(self.listItemClick) + self.listWidget.itemClicked.connect(self.listItemClick) + self.listWidget.itemDoubleClicked.connect(self.listItemDoubleClick) layout.addWidget(self.listWidget) self.setLayout(layout) @@ -76,4 +77,7 @@ class LabelDialog(QDialog): # PyQt5: AttributeError: 'str' object has no attribute 'trimmed' text = tQListWidgetItem.text().strip() self.edit.setText(text) + + def listItemDoubleClick(self, tQListWidgetItem): + self.listItemClick(tQListWidgetItem) self.validate()