From 957450c0f69a774ce0b4ba9af4a9c2b5c2b9f5a2 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Wed, 17 Aug 2022 21:28:15 +0100 Subject: [PATCH] Use QPlainTextEdit to edit cells --- app/playlists.py | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/app/playlists.py b/app/playlists.py index 7aff3c0..d40055d 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -26,8 +26,9 @@ from PyQt5.QtWidgets import ( QLineEdit, QMainWindow, QMenu, - QStyledItemDelegate, QMessageBox, + QPlainTextEdit, + QStyledItemDelegate, QTableWidget, QTableWidgetItem, QTextEdit, @@ -81,27 +82,18 @@ columns["row_notes"] = Column(idx=8, heading=Config.COLUMN_NAME_NOTES) class NoSelectDelegate(QStyledItemDelegate): """ + This originally used the following link to not select text on edit; + however, using a QPlainTextBox means a) text isn't selected anyway and + b) it provides a multiline edit. + https://stackoverflow.com/questions/72790705/ dont-select-text-in-qtablewidget-cell-when-editing/72792962#72792962 """ def createEditor(self, parent, option, index): - editor = super().createEditor(parent, option, index) - if isinstance(editor, QLineEdit): - # def deselect(): - # # Important! First disconnect, otherwise editor.deselect() - # # will call again this function - # editor.selectionChanged.disconnect(deselect) - # editor.deselect() - # editor.selectionChanged.connect(deselect) - # self.old_editor = editor - textedit = QTextEdit(parent) - textedit.setPlainText(editor.text()) - return textedit - - # def destroyEditor(self, editor, index): - # self.old_editor.setText(editor.toPlainText()) - # super().destroyEditor(self, self.old_editor, index) + if isinstance(index.data(), str): + return QPlainTextEdit(parent) + return super().createEditor(parent, option, index) class PlaylistTab(QTableWidget): # Qt.UserRoles @@ -1108,9 +1100,6 @@ class PlaylistTab(QTableWidget): self._get_section_timing_string(section_time, no_end=True) ) - # Ensure content is visible by wrapping cells - self.resizeRowsToContents() - # Scroll to put next track Config.SCROLL_TOP_MARGIN from the # top. Rows number from zero, so set (current_row - # Config.SCROLL_TOP_MARGIN + 1) row to be top row