How to know when field is edited within QTableView
I have a table view within a window with many other widgets, and would like to disable other widgets if a field is edited within the table view. I would like to enable a commit button also.
Code:
model = new jobItemSortFilterProxyModel();
model->setSourceModel(sourcemodel);
sourcemodel->setTable("jobitem");
sourcemodel->select();
Pretty straight forward. How can I pick up when the various delegates, ie. text edit or spin box change the data?
The dataChanged() signal fires when setData is called, not when editing begins.
Derek
Re: How to know when field is edited within QTableView
Create a custom delegate and emit signals from:
- QAbstractItemDelegate::setEditorData() (edit begins)
- QAbstractItemDelegate::setModelData() (edit ends)
You can easily achieve this by subclassing the default delegate implementation QItemDelegate, adding a couple of signals, overriding methods listed above and emitting corresponding signals from there.
Code:
void MyItemDelegate
::setEditorData(QWidget* editor,
const QModelIndex
& index
) const {
emit editBegins();
}
{
emit editEnds();
}
Re: How to know when field is edited within QTableView
For simple uses you might just connect to the activated() signal of the view, but be warned, that it'll not handle all possible situations. It depends which edit triggers you use.
Re: How to know when field is edited within QTableView
For completeness, emitting a signal from a const method:
Code:
void MyItemDelegate
::setEditorData(QWidget* editor,
const QModelIndex
& index
) const {
emit const_cast<MyItemDelegate*>(this)->editBegins();
}
http://lists.trolltech.com/qt-intere...ad01411-0.html