From 3f32a66c32224de7016e938a1eeb33b397b9b50f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 28 May 2023 12:43:29 +0530 Subject: [PATCH] Fix #2021367 [Edit cell not longer select all content](https://bugs.launchpad.net/calibre/+bug/2021367) --- src/calibre/gui2/complete2.py | 12 +++++++++++- src/calibre/gui2/dialogs/authors_edit.py | 4 ++-- src/calibre/gui2/library/delegates.py | 6 ++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/complete2.py b/src/calibre/gui2/complete2.py index b0026a0c88..850733f7ae 100644 --- a/src/calibre/gui2/complete2.py +++ b/src/calibre/gui2/complete2.py @@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en' from qt.core import ( QLineEdit, QAbstractListModel, Qt, pyqtSignal, QObject, QKeySequence, QAbstractItemView, - QApplication, QListView, QPoint, QModelIndex, QEvent, + QApplication, QListView, QPoint, QModelIndex, QEvent, pyqtProperty, QStyleOptionComboBox, QStyle, QComboBox, QTimer, sip) from calibre.constants import ismacos @@ -515,6 +515,16 @@ class EditWithComplete(EnComboBox): def text(self): return self.lineEdit().text() + + @pyqtProperty(str) + def currentText(self): + return self.lineEdit().text() + + @currentText.setter + def currentText(self, text): + self.setText(text) + self.lineEdit().selectAll() + def selectAll(self): self.lineEdit().selectAll() diff --git a/src/calibre/gui2/dialogs/authors_edit.py b/src/calibre/gui2/dialogs/authors_edit.py index 2de105021c..d93aad884e 100644 --- a/src/calibre/gui2/dialogs/authors_edit.py +++ b/src/calibre/gui2/dialogs/authors_edit.py @@ -30,8 +30,8 @@ class ItemDelegate(QStyledItemDelegate): def setEditorData(self, editor, index): name = str(index.data(Qt.ItemDataRole.DisplayRole) or '') - editor.setText(name) - editor.lineEdit().selectAll() + n = editor.metaObject().userProperty().name() + editor.setProperty(n, name) def setModelData(self, editor, model, index): authors = string_to_authors(str(editor.text())) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 546178051f..d025d67b21 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -381,7 +381,8 @@ class CompleteDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ return editor def setEditorData(self, editor, index): - editor.setText(get_val_for_textlike_columns(index)) + n = editor.metaObject().userProperty().name() + editor.setProperty(n, get_val_for_textlike_columns(index)) def setModelData(self, editor, model, index): if isinstance(editor, EditWithComplete): @@ -494,7 +495,8 @@ class CcTextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ return editor def setEditorData(self, editor, index): - editor.setText(get_val_for_textlike_columns(index)) + n = editor.metaObject().userProperty().name() + editor.setProperty(n, get_val_for_textlike_columns(index)) def setModelData(self, editor, model, index): val = editor.text() or ''