When I use tableview to make a table control ,something about singnal dataChanged() really confused me!
If the parameters "const QModelIndex & topLeft, const QModelIndex & bottomRight" are the same index, the view only will update exactly the cell which is pointed by the index.But if topLeft!=bottomRight, the entire tableview will be refreshed no matter whereever the topLeft or bottomRight is.
I looked up the src file of qt, in qabstractitemview.cpp
{
// Single item changed
if (topLeft == bottomRight && topLeft.isValid()) {
if (d->hasEditor(topLeft)) {
if (delegate) {
delegate->setEditorData(d->editorForIndex(topLeft), topLeft);
}
}
if (isVisible() && !d->delayedLayout.isActive()) {
// otherwise the items will be update later anyway
d->viewport->update(visualRect(topLeft));
}
return;
}
d->updateEditorData(topLeft, bottomRight);
if (!isVisible() || d->delayedLayout.isActive())
return; // no need to update
/* ---> */ d->viewport->update(); /* <--- */
}
connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(dataChanged(QModelIndex,QModelIndex)));
void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
// Single item changed
Q_D(QAbstractItemView);
if (topLeft == bottomRight && topLeft.isValid()) {
if (d->hasEditor(topLeft)) {
QAbstractItemDelegate *delegate = d->delegateForIndex(topLeft);
if (delegate) {
delegate->setEditorData(d->editorForIndex(topLeft), topLeft);
}
}
if (isVisible() && !d->delayedLayout.isActive()) {
// otherwise the items will be update later anyway
d->viewport->update(visualRect(topLeft));
}
return;
}
d->updateEditorData(topLeft, bottomRight);
if (!isVisible() || d->delayedLayout.isActive())
return; // no need to update
/* ---> */ d->viewport->update(); /* <--- */
}
To copy to clipboard, switch view to plain text mode
I guess the red code means the entire tableview will be updated! Am I right?
Bookmarks