Hi all:
i create a 2*2 table, and i create my own simple model, just re-implementing the data() function. The code is as follows:
int role) const
{
int column=index.column();
qDebug()<<"row="<<index.row()<<"column="<<index.column()<<"data role="<<role;
if(role==Qt::DisplayRole){
//qDebug()<<"row="<<index.row()<<"column="<<index.column()<<"display="<<role;
return column+3;
}
}
QVariant MyStandardItemModel::data(
const QModelIndex & index,
int role) const
{
int column=index.column();
qDebug()<<"row="<<index.row()<<"column="<<index.column()<<"data role="<<role;
if(role==Qt::DisplayRole){
//qDebug()<<"row="<<index.row()<<"column="<<index.column()<<"display="<<role;
return column+3;
}
else return QStandardItemModel::data(index,role);
}
To copy to clipboard, switch view to plain text mode
when i run my program , i think the data() function should be called 4 times, but actually it is called many times,
QQ截图20140116143644.jpg
It is confused me.
My questions are:
1.why the data() function is called so many times but not 4 times?
2.why the item has 7 roles while i don't set roles to item. For example:
row= 0 column= 0 data role= 6
row= 0 column= 0 data role= 7
row= 0 column= 0 data role= 9
row= 0 column= 0 data role= 10
row= 0 column= 0 data role= 1
row= 0 column= 0 data role= 0
row= 0 column= 0 data role= 8
Is this the default setting or i missing something?
Bookmarks