PDA

View Full Version : QtableView performances



bacou
14th December 2010, 21:50
Hi,

I am using a qtableview with a model to display data, a lot of data
I implemented the data(const QModelIndex &index, int role) function but it looks like this function is called a lot: (size of each item in Qt::ItemDataRole enum) * number of items in my model which is the way it's apparently set up in Qt.

but for example if I scroll down to show only one morerow the data function is called again on each item of my model instead of only for the new items in the row I am just showing

Anyway to cache it or something?

Thank you

wysota
15th December 2010, 00:31
You can cache the value you return from data() if that helps you anything. Qt won't cache it on its own. You can also reimplement itemData() to be somewhat faster than the naive loop over data() calls.

calmspeaker
15th December 2010, 02:31
"this function is called a lot: (size of each item in Qt::ItemDataRole enum) * number of items in my model which is the way it's apparently set up in Qt."
Is it true?
I guess that qt will call the function only if the data is needed to display.

wysota
15th December 2010, 09:56
It depends. If you have per-pixel scrolling enabled then Qt has to recalculate item position taking into consideration not only the visible items but also items before it. That's why it helps a lot to set that items have uniform size in the listview. Then only the first item is checked and then result is multiplied by the number of items.

bacou
15th December 2010, 19:13
I already have fixed size policy and scrollperitem enabled actually
my data function does not compute anything, just call a function that return a precomputed QVariant corresponding to the role on my object at the index in parameter
Is this problem considered as a bug/issue ?
I use resizeSection on both of my headers to display as much data as I can but the more I display the more data() is called which is my issue

wysota
16th December 2010, 08:13
I already have fixed size policy and scrollperitem enabled actually
Not fixed size policy but QListView::uniformItemSizes. There is no equivalent of that in QTableView. If you scroll per pixel there, your data will always be queried very often.