Detect when the content of a cell of QTableView is changed
Hi all,
I need monitoring the changes in the data content of a cell of QTableView.
I have a QTableView widget into QMainWindow.
I have tried with the QAbstractItemView signals, the slots are called in my QMainWindow class, but neither of them accomplish the target that I need.
I have tried with the currentChanged( const QModelIndex & current, const QModelIndex & previous ) signal of QItemSelectionModel, as above the slot is called, but itsn't accomplish the target that I need too.
I make the connects like this:
There are any signal / slot / method or similar that I could use to accomplish my target?
Best regards.
Re: Detect when the content of a cell of QTableView is changed
You are looking in the wrong direction. To get a signal when the data changes you need to be looking at the data model not the view: QAbstractItemModel::dataChanged() for example.
Re: Detect when the content of a cell of QTableView is changed
When i first started i tried QTableView and had endless problems myself
I then switched to Qtable Widget. And cell changed events and so forth are much easier to use.
Hope this helps
Re: Detect when the content of a cell of QTableView is changed
Quote:
Originally Posted by
ChrisW67
You are looking in the wrong direction. To get a signal when the data changes you need to be looking at the data model not the view:
QAbstractItemModel::dataChanged() for example.
Hi ChrisW67,
I have used this new code:
Code:
connect(ui->myTableView->model(), SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(onDataChanged(const QModelIndex&, const QModelIndex&)));
...
void myClass::onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
qDebug() << "the cell has changed";
}
And works fine!
Thank you.
Re: Detect when the content of a cell of QTableView is changed
Quote:
Originally Posted by
qt_developer
Hi ChrisW67,
I have used this new code:
Code:
connect(ui->myTableView->model(), SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(onDataChanged(const QModelIndex&, const QModelIndex&)));
...
void myClass::onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
qDebug() << "the cell has changed";
}
And works fine!
Thank you.
Hi can you give the whole code ?
Re: Detect when the content of a cell of QTableView is changed
Quote:
Hi can you give the whole code ?
What you do in response to a dataChanged() signal is specific to your application. Any "whole code" for this thread would probably have no meaning in your application.
I suggest you start with reading about Qt Model/View Programming in the documentation, look at the Model/View tutorial, and finally look at some of the 19 examples of Model/View programming that come with Qt.
You will probably learn enough in that to understand how to use the QAbstractItemModel::dataChanged() signal in your own application.