It seems now to be resolved with:
59 # In a standard QTableView, editor parent is the viewport.
60 # viewport parent is the table.
61 try:
62 + from PySide6.QtCore import QTimer
63 viewport = editor.parent()
64 table = viewport.parent()
65
69 if idx.isValid():
70 new_idx = table.model().index(idx.row() + 1, idx.column())
71 if new_idx.isValid():
71 - print(f"Moving to next row: {new_idx.row()}")
72 - # This direct call is likely the source of the warning
73 - table.setCurrentIndex(new_idx)
74 - table.edit(new_idx)
72 + print(f"Scheduling move to next row: {new_idx.row()}")
73 + # Defer the move to the next event loop iteration
74 + def do_move():
75 + table.setCurrentIndex(new_idx)
76 + table.edit(new_idx)
77 + QTimer.singleShot(0, do_move)
78 else:
79 print(f"Parent is not QTableView: {type(table)}")
80 except Exception as e:
Stefan de KoninkI'll give your suggestion a go.
https://chiselapp.com/user/luziferius/repository/ArcheMapper/file?ci=tip&name=archemapper/ui/model_views.py&ln=79-110 Here's an implementation tabbing horizontally through a heterogenous tree model with potentially empty parents (overwriting the default vertical movement).
An implementation for a table model should be much simpler
For switching to the next item via Enter key, you'd intercept that by using an event filter: You can use the delegate class for this.
def eventFilter(self, object, event: QEvent | QKeyEvent, /):
if (object == self._editor
and event.type() == QEvent.Type.KeyPress
and event.key() in (Qt.Key.Key_Return, Qt.Key.Key_Enter)):
self.commitData.emit(object)
self.closeEditor.emit(object, QStyledItemDelegate.EndEditHint.EditNextItem)
return True
return super().eventFilter(object, event)
Then the QLineEdit does not need any further navigation logic
ThomasFor switching to the next item via Enter key, you'd intercept that by using an event filter: You can use the delegate class for this.
def eventFilter(self, object, event: QEvent | QKeyEvent, /):
if (object == self._editor
and event.type() == QEvent.Type.KeyPress
The remaining issue seems to be in this part. When I enable the delegate on both widgets, it fails.
self.journey_delegate = JourneyDelegate(self.tdt_model, self.day_type_model, self)
# Apply RightToLeft to the left table
self.table_widget.left_table.setLayoutDirection(Qt.RightToLeft)
self.table_widget.left_table.setItemDelegate(self.journey_delegate)
# self.table_widget.right_table.setItemDelegate(self.journey_delegate)
When I explicitly make a left delegate and right delegate error gone.
Stefan de KoninkThe remaining issue seems to be in this part. When I enable the delegate on both widgets, it fails.
self.journey_delegate = JourneyDelegate(self.tdt_model, self.day_type_model, self)
# Apply RightToLeft to the left table
self.table_widget.left_table.setLayoutDirection(Qt.RightToLeft)
self.table_wid
Yeah. Don't share the delegate between views.