Use QPlainTextEdit to edit cells

This commit is contained in:
Keith Edmunds 2022-08-17 21:28:15 +01:00
parent 20e9880a03
commit 957450c0f6

View File

@ -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