Value changed in a QTableView field
I've searched a bit, but could not found how to do this.
Have got a QSqlTableModel and a QTableView which I use to show the data.
I would like to know if, when I change the value of a field in QTableView, a signal is emitted, because I need to call a function when the user edit a field.
Don't care, now, to change the data directly in database, I'll do the commit manually.
Re: Value changed in a QTableView field
I never used QSqlTableModel, but as far as QTableView if you want users to edit data I think you should use QTableWidget instead. Assuming you're using QTCreator just right clik on QTableWidget choose 'Go to Slot... ' option, and a list with Signal will apear. I think QTableWidget::itemChanged ( QTableWidgetItem * item ) will do.
Re: Value changed in a QTableView field
For every model the QAbstractItemModel::dataChanged() signal is emitted when contents of the model change. So simply go through QAbstractItemView::model() to find the appropriate signal and connect to it.
Re: Value changed in a QTableView field
Quote:
Originally Posted by
john_god
I never used QSqlTableModel, but as far as QTableView if you want users to edit data I think you should use
QTableWidget instead.
Just a remark here: QTableWidget is basically a QTableModel a filter and a QTableView put into one convenience widget. When the model supports data for the Qt::EditRole, then QTableView will be perfectly able to support editing of data.
Re: Value changed in a QTableView field
@wysota:
thank you! that was what I was looking for!
@john_god:
franz is right, no problem at all editing data in QTableView!
By the way here is how I solved it:
and then I implemented myFunction() to do what I need to do ;)