ChatCrawlersearch across public Telegram Open the app
Q

Qt for Python (PySide/Shiboken)

386 members
S
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:
T
Do you want different edit directions based on how the user completes the editor? (So Tab moves columns, Enter moves rows?)
S
Yes I am making a open source timetable application. So times are entered downwards.
T
Completing with Key_Tabulator should move to the right?
T
If not, it is better to overwrite QTableView.moveCursor()
Sadly in my 'bigger' application I still have the error, when applying the same fix.
S
I'll give your suggestion a go.
S
After implementing it, the commit error is still active somewhere. Hence I still have to see why / what.
Whenever you do QTimer.singleShot(0, something), it is very likely that using a Qt.ConnectionType.QueuedConnection in connect() is the better approach
But my 'bigger' application still has the issue.
S
Already transplanted the delegates, and they still trigger.
T
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
Applied it. Still end up with: QAbstractItemView::commitData called with an editor that does not belong to this view QAbstractItemView::closeEditor called with an editor that does not belong to this view
(this is in my full example)
My guess is that the EventFilter is the one triggering the close editor at this time. So there is something going on between the delegate in my full thing an the minimum reproducable example
But the interesting part here is that the thing also triggers, if the emit is disabled at the eventFilter.
Maybe found something...
S
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.
So for days searching the cause... it would have been very nice to get a warning if it was done so :-o
S
Your event filter part was the second part of the solution.
Open in Telegram Каталог площадок Искать в ChatCrawler

A snapshot of an open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog