I have been trying to get a tableview and table model to work at a reasonable speed lately and it has failed. If I add 100 rows it takes about 14 seconds to refresh the view and forget about trying to scroll...every time I use the scrollbar it lags, skipping lines all over the place.
I tried to find what is taking so much of the systems resources, by putting qDebug()'s in my function and found that it calls the data() method continuously. It calls this method at least 5 times for each index and each role. Since I have 9 columns and there are seven roles it seems to call the method 31500 times then calls the header. It then starts over again without stopping. None of the data changes and I don't touch the screen while all this happening. It just keeps on calling data.
I hope what I wrote made some sense. If you could help that would be great.
My data method is something like this:
QVarient class
::data(const QModelIndex &index,
int role
) const{
if(!index.isValid())
if(role == Qt:AlignmentRole)
return int(Qt::AlignRight | Qt::AlignVCenter);
else if(role == Qt::DisplayRole)
switch(index.column())
{
case 0: return 1;
case 1: return 1;
case 2: return 1;
case 3: return 1;
case 4: return 1;
case 5: return 1;
case 6: return 1;
case 7: return 1;
case 7: return 1;
}
}
else
}
QVarient class::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant;
if(role == Qt:AlignmentRole)
return int(Qt::AlignRight | Qt::AlignVCenter);
else if(role == Qt::DisplayRole)
switch(index.column())
{
case 0: return 1;
case 1: return 1;
case 2: return 1;
case 3: return 1;
case 4: return 1;
case 5: return 1;
case 6: return 1;
case 7: return 1;
case 7: return 1;
}
}
else
return QVariant();
}
To copy to clipboard, switch view to plain text mode
Bookmarks