Edit partially working
setData called but not implemented ESC not detected in edit
This commit is contained in:
parent
07669043eb
commit
0690a66806
@ -725,7 +725,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
playlist_tab = PlaylistTab(
|
playlist_tab = PlaylistTab(
|
||||||
musicmuster=self,
|
musicmuster=self,
|
||||||
session=session,
|
|
||||||
playlist_id=playlist.id,
|
playlist_id=playlist.id,
|
||||||
signals=self.signals,
|
signals=self.signals,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -143,7 +143,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
elif role == Qt.ItemDataRole.DecorationRole:
|
elif role == Qt.ItemDataRole.DecorationRole:
|
||||||
pass
|
pass
|
||||||
elif role == Qt.ItemDataRole.EditRole:
|
elif role == Qt.ItemDataRole.EditRole:
|
||||||
pass
|
return self.edit_role(row, column, prd)
|
||||||
elif role == Qt.ItemDataRole.ToolTipRole:
|
elif role == Qt.ItemDataRole.ToolTipRole:
|
||||||
pass
|
pass
|
||||||
elif role == Qt.ItemDataRole.StatusTipRole:
|
elif role == Qt.ItemDataRole.StatusTipRole:
|
||||||
@ -209,6 +209,20 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
|
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
||||||
|
def edit_role(self, row: int, column: int, prd: PlaylistRowData) -> QVariant:
|
||||||
|
"""
|
||||||
|
Return text for editing
|
||||||
|
"""
|
||||||
|
|
||||||
|
if column == Col.TITLE.value:
|
||||||
|
return QVariant(prd.title)
|
||||||
|
if column == Col.ARTIST.value:
|
||||||
|
return QVariant(prd.artist)
|
||||||
|
if column == Col.NOTE.value:
|
||||||
|
return QVariant(prd.note)
|
||||||
|
|
||||||
|
return QVariant()
|
||||||
|
|
||||||
def flags(self, index: QModelIndex) -> Qt.ItemFlag:
|
def flags(self, index: QModelIndex) -> Qt.ItemFlag:
|
||||||
"""
|
"""
|
||||||
Standard model flags
|
Standard model flags
|
||||||
|
|||||||
@ -94,7 +94,6 @@ class EscapeDelegate(QStyledItemDelegate):
|
|||||||
def eventFilter(self, editor: QObject, event: QEvent):
|
def eventFilter(self, editor: QObject, event: QEvent):
|
||||||
"""By default, QPlainTextEdit doesn't handle enter or return"""
|
"""By default, QPlainTextEdit doesn't handle enter or return"""
|
||||||
|
|
||||||
print(">>EscapeDelegate event handler")
|
|
||||||
if event.type() == QEvent.Type.KeyPress:
|
if event.type() == QEvent.Type.KeyPress:
|
||||||
key_event = cast(QKeyEvent, event)
|
key_event = cast(QKeyEvent, event)
|
||||||
print(key_event)
|
print(key_event)
|
||||||
@ -114,6 +113,19 @@ class EscapeDelegate(QStyledItemDelegate):
|
|||||||
# self.closeEditor.emit(editor)
|
# self.closeEditor.emit(editor)
|
||||||
# return True
|
# return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def setEditorData(self, editor, index):
|
||||||
|
value = index.model().data(index, Qt.ItemDataRole.EditRole)
|
||||||
|
editor.setPlainText(value.value())
|
||||||
|
|
||||||
|
def setModelData(self, editor, model, index):
|
||||||
|
print("setModelData called")
|
||||||
|
value = editor.toPlainText()
|
||||||
|
model.setData(index, value, Qt.ItemDataRole.EditRole)
|
||||||
|
|
||||||
|
def updateEditorGeometry(self, editor, option, index):
|
||||||
|
editor.setGeometry(option.rect)
|
||||||
|
|
||||||
# class EscapeDelegate(QStyledItemDelegate):
|
# class EscapeDelegate(QStyledItemDelegate):
|
||||||
# """
|
# """
|
||||||
# - increases the height of a row when editing to make editing easier
|
# - increases the height of a row when editing to make editing easier
|
||||||
@ -203,7 +215,6 @@ class PlaylistTab(QTableView):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
musicmuster: "Window",
|
musicmuster: "Window",
|
||||||
session: scoped_session,
|
|
||||||
playlist_id: int,
|
playlist_id: int,
|
||||||
signals: "MusicMusterSignals",
|
signals: "MusicMusterSignals",
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user