QTableWidget editing started?
-
Hi, is there any signal to detect when a cell has begun editing its data in
QTableWidget
?
I am usingQTableWidget
and assigningQTableWidgetItem
to all its cells. There are multiple signals thatQTableWidget
provides to give me the state of its cells, e.g.cellActivated(int row, int column) cellChanged(int row, int column) cellClicked(int row, int column) cellDoubleClicked(int row, int column) cellEntered(int row, int column) cellPressed(int row, int column) currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)
None of these signals tells me if the cell is being edited. The user can begin editing by many different methods set by using
EditTriggers
, so I cannot depend on a single signal from the above list to be sure that the editing has begun. Is there any way to get the signal or make my own signal (e.g.cellEditingBegun(int row, int column)
) to know when a cell is being edited? I (preferably) do not want to use any other class other thanQTableWidget
andQTableWidgetItem
since these 2 classes are enough for what I am trying to get done. -
@CJha
void QAbstractItemView::edit(const QModelIndex &index) is a slot which is called to start editing. It's not markedvirtual
so I don't think you can override it.void QAbstractItemView::openPersistentEditor(const QModelIndex &index) is called to open the editor, but again it's not
virtual
.Editing is handled by a
QAbstractItemDelegate
. You could set your own via void QAbstractItemView::setItemDelegate(QAbstractItemDelegate *delegate). You could have that call the table widget's current one for all purposes for the implementation. QAbstractItemDelegate::createEditor() is the method called when starting to edit, and isvirtual
, so if you override this you will know when editing starts.That's what I know.
UPDATE
I just found QTableWidget: signal to detect start of cell edit. This confirms what I have written. The accepted solution saysOne way is to reimplement the
edit
method of the table-widget, and emit a custom signal:I had not spotted that there is another
QAbstractItemView::edit()
overload, bool QAbstractItemView::edit(const QModelIndex &index, QAbstractItemView::EditTrigger trigger, QEvent *event), which isvirtual
so you can override it. However, it isprotected
, you would need to subclass yourQTableWidget
to override it. The item delegate approach can be used without having to subclassQTableWidget
orQTableWidgetItem
.Also looks like I and @VRonin responded similarly in this forum at https://forum.qt.io/topic/115066/qtablewidget-editing-signal