QTableView: how to do something while editing the beginning and end?

Are there any signals (I cannot find anything in the documents) emitted when the user starts and finishes editing the cell of the QTableView widget?

I want to execute some function from the table model, then the user starts editing eny cell and performs another function when the user finishes editing. How can i do this?

+4
source share
4 answers

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

Also there is a dataChanged signal in QAbstractItemModel.

+4
source

I would get a class from QTableView and redefine the selectionChanged function to implement a specific behavior when the user starts editing a cell, and also redefine the dataChanged function to implement a specific behavior after the cell has been changed.

0
source

Like the graphite above, I usually use dataChanged in my model, usually QSqlTableModel, to find out if editing has finished. But I agree that it would be wise to have signals for more detailed user actions in the QTableView itself.

 connect(model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(updatePlot())); 
0
source

The problem with the dataChanged signal is that it is also generated when programmatically changing the data (setData). If the program calls setData (), and the slot should not start, then the only solution is to implement a custom delegate.

QAbstractItemView has virtual methods commitData and closeEditor, but they do not accept the index as a parameter, and I'm not 100% sure. currentIndex () will always be correct ... (for sure, QAIV does not rely on this because it has constant editors, so it has an internal hash).

0
source

Source: https://habr.com/ru/post/1343733/


All Articles