View Full Version : questions about datachanged() in model/view programming

8th September 2008, 10:46
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

connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(dataChanged(QModelIndex,QModelIndex)));

void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
// Single item changed
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->updateEditorData(topLeft, bottomRight);
if (!isVisible() || d->delayedLayout.isActive())
return; // no need to update
/* ---> */ d->viewport->update(); /* <--- */

I guess the red code means the entire tableview will be updated! Am I right?:(

9th September 2008, 00:48
The code invokes update() on the viewport. That's the visible part of the view.