Use QPlainTextEdit to edit cells
This commit is contained in:
parent
20e9880a03
commit
957450c0f6
@ -26,8 +26,9 @@ from PyQt5.QtWidgets import (
|
|||||||
QLineEdit,
|
QLineEdit,
|
||||||
QMainWindow,
|
QMainWindow,
|
||||||
QMenu,
|
QMenu,
|
||||||
QStyledItemDelegate,
|
|
||||||
QMessageBox,
|
QMessageBox,
|
||||||
|
QPlainTextEdit,
|
||||||
|
QStyledItemDelegate,
|
||||||
QTableWidget,
|
QTableWidget,
|
||||||
QTableWidgetItem,
|
QTableWidgetItem,
|
||||||
QTextEdit,
|
QTextEdit,
|
||||||
@ -81,27 +82,18 @@ columns["row_notes"] = Column(idx=8, heading=Config.COLUMN_NAME_NOTES)
|
|||||||
|
|
||||||
class NoSelectDelegate(QStyledItemDelegate):
|
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/
|
https://stackoverflow.com/questions/72790705/
|
||||||
dont-select-text-in-qtablewidget-cell-when-editing/72792962#72792962
|
dont-select-text-in-qtablewidget-cell-when-editing/72792962#72792962
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
editor = super().createEditor(parent, option, index)
|
if isinstance(index.data(), str):
|
||||||
if isinstance(editor, QLineEdit):
|
return QPlainTextEdit(parent)
|
||||||
# def deselect():
|
return super().createEditor(parent, option, index)
|
||||||
# # 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)
|
|
||||||
|
|
||||||
class PlaylistTab(QTableWidget):
|
class PlaylistTab(QTableWidget):
|
||||||
# Qt.UserRoles
|
# Qt.UserRoles
|
||||||
@ -1108,9 +1100,6 @@ class PlaylistTab(QTableWidget):
|
|||||||
self._get_section_timing_string(section_time, no_end=True)
|
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
|
# Scroll to put next track Config.SCROLL_TOP_MARGIN from the
|
||||||
# top. Rows number from zero, so set (current_row -
|
# top. Rows number from zero, so set (current_row -
|
||||||
# Config.SCROLL_TOP_MARGIN + 1) row to be top row
|
# Config.SCROLL_TOP_MARGIN + 1) row to be top row
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user