Question

Are there any signals (I cannot find anything in the docs) emitted when user starts and ends the QTableView widget cell edititing?

I want to execute some function from table model then user begins edit eny cell and execute another function when user ends editing. How can I do this?

Was it helpful?

Solution

Actions when user starts/ends editing can be done by implementing your own Delegate.

Also there is dataChanged signal in QAbstractItemModel.

OTHER TIPS

The problem with the dataChanged signal is that it's also emitted when changing data programmatically (setData). If the program calls setData(), and the slot shouldn't be triggered, then the only solution is to implement a custom delegate indeed.

QAbstractItemView has virtual methods commitData and closeEditor but they don't take the index as parameter and I'm not 100% sure currentIndex() will always be correct... (for sure QAIV doesn't rely on that, because of persistent editors, so it has an internal hash).

I would derive a class from QTableView and override the function selectionChanged to implement specific behaviour when the user begins to edit the cell and also override the function dataChanged to implement specific behaviour for after the cell has been modified.

Like graphite suggests above, I typically use dataChanged in my model, typically QSqlTableModel, to find out when editing has ended. But I agree it would make sense to have signals for more detailed user actions in QTableView itself.

connect(model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(updatePlot()));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top