• 5580阅读
  • 4回复

跪求谁给解释下这个函数dataChanged的参数 [复制链接]

上一主题 下一主题
离线jinyu
 
只看楼主 倒序阅读 楼主  发表于: 2009-04-16
void QAbstractItemModel::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight )   [signal]
参数如何使用。文档说的太少了
离线chrisopal
只看该作者 1楼 发表于: 2009-04-16
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
        }
    }
    //同理, 处理某一行变化时
   .......
}
离线jinyu
只看该作者 2楼 发表于: 2009-04-16
恩,谢谢,可是topLeft ==  bottomRight ??什么意思呢?
离线chrisopal
只看该作者 3楼 发表于: 2009-04-17
表示只有当前cell变化了,它的QModelIndex就是topLeft , 也是bottomRight 它们都指向同一个cell
离线jinyu
只看该作者 4楼 发表于: 2009-04-17
恩,明白了,呵呵,谢谢你啊。
快速回复
限100 字节
 
上一个 下一个