topLeft, bottomRight 确定了一个selection range, 比如可以是三行三列, 一行,一列, 甚至就一个Cell,
你可以把这个signal连到一个slot, 比如说
handleDataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight )
void handleDataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight )
{
//如果我想处理当row = 3, column = 2 的QModelIndex的数组变化时
if( topLeft == bottomRight &&
topLeft .row() == 2 &&
topLeft .column() == 1 )//
{
QVariant v = model.data( topLeft );
//do something
}
//如果你想处理的是比如说第三列变化时,做一些事
if( topLeft.column() == bottomRight .column() &&
topLeft.column() == 2 )
{
for( int r = topLeft.row(); r < bottomRight .row(); r++ )
{
QVariant v = model.data( QModelIndex( r, 2 ) )
//doing something nex
}
}
//同理, 处理某一行变化时
.......
}