Nikolay Kornushkov
Nikolay Kornushkov

Reputation: 124

QTableView: how to do something on start/end editing?

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?

Upvotes: 4

Views: 3306

Answers (4)

David Faure
David Faure

Reputation: 1997

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).

Upvotes: 1

graphite
graphite

Reputation: 2958

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

Also there is dataChanged signal in QAbstractItemModel.

Upvotes: 5

Olli Savolainen
Olli Savolainen

Reputation: 692

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()));

Upvotes: 0

Gary Miller
Gary Miller

Reputation: 43

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.

Upvotes: 0

Related Questions