PDA

View Full Version : QTableView - scroll performance changed from 4.0 to 4.1 and 4.2



budul
8th November 2006, 10:45
Hi all,
i need to move my code from 4.0 to 4.2. But unfortunately found big problem in performance when scrolling in QTableView with many custom widgets loaded in the table and in "Edit Mode". One can easily reproduce this phenomena with use of QT4 example - SpinBoxDelegate under Item View examples. Just modify main.cpp from:


QStandardItemModel model(4, 2);

for (int row = 0; row < 4; ++row)
{
for (int column = 0; column < 2; ++column)
{
QModelIndex index = model.index(row, column, QModelIndex());
model.setData(index, QVariant((row+1) * (column+1)));
}
}

to


QStandardItemModel model(400, 200);

for (int row = 0; row < 400; ++row)
{
for (int column = 0; column < 200; ++column)
{
QModelIndex index = model.index(row, column, QModelIndex());
model.setData(index, QVariant((row+1) * (column+1)));
tableView.openPersistenEditor(index);
}
}

I know it takes so looong time to load all the widgets to the table, but this is not big issue for me, because it starts only once.
Anyway there had to be a significant change in QT from 4.0. Because with 4.0 the same code had no problem with sroll at all.

Any ideas? Did i miss something?

Thanks a lot!
B.

wysota
8th November 2006, 11:59
I'd say it's a misdesign on your side. Do you really need 80000 editors open at the same time? You won't modify all the items at once, will you? I modified your code, as I'm not patient enough to wait an hour before the application starts up, so that it only opened 5000 editors and it still behaved awfully. Each time I scrolled something, all the widgets needed to be repositioned - first they disappeared from the view and then I turned off the application before they had a chance to show up again (again, I'm not patient enough). You should really reconsider changing your design. The easiest way would be to only use editors for a single row and for all the other rows just paint the same set of controls a spinbox has so that it can mimic its look. I'm sure it'll get a looooooot faster this way.

budul
8th November 2006, 13:01
Yes, you are surely right. Actualy i'm using 20x10 widgets, just to fill screen. Then i'm reusing them somehow. Simply i needed to have all widgets ready for edit and they are more complicated in real. Imagine some stock monitoring application with progress bars and custom designed widgets to edit and monitor courses. Probably "not focuesd ones" i should just paint. But anyway i have to solve my transfer to 4.2 from 4.0. And in 4.0 scroll was not a problem at all. So what changed here in the meantime? Is there another way out than change in design? Of course, to stay with 4.0 is not the answer. ;)
Thanks again!
B.

wysota
8th November 2006, 14:34
Probably something was optimised or fixed, but as you are using the framework in a very... emmm... uncommon way :) the probably that optimisation turned out to be a slowdown for you or you might have been benefiting from a bug and when the bug was fixed the benefit vanished.

Maybe you should use a QScrollArea filled with widgets instead of a table view?

budul
8th November 2006, 20:14
Please, tell me how one can easily paint widget which contains 3-4 other widgets to item in TableView. Simply i need these features of TableView as resizing columns, hiding columns. That's why i'm using table.

Attached is the picture of what i've got and need. How this can be done more optimized way?
Thanks a lot!
B.

wysota
8th November 2006, 21:07
Please, tell me how one can easily paint widget which contains 3-4 other widgets to item in TableView.

Create a custom widget with the other widgets inside it (in a layout) and then use QAbstractItemView::setIndexWidget() to set the widget. If you need the widget to be able to edit the data inside the model then set it as an editor instead.

budul
8th November 2006, 21:32
That's exactly what i'm doing, but via delegate. But my problem is that even if i set 20x10 widgets to the table i've got very poor performance. How can i create table with 20x10 custom widgets and will have good response from the GUI in 4.2?

I really can't have just text in the cells. :-(

Thanks again.
B.

wysota
8th November 2006, 23:36
Each subsequent permanent editor takes longer to add to the view, so you might want to avoid those. Using index widgets should be faster as they are not updated by the view.

In your case maybe it would be best to get rid of the view and just emulate the columns by using a QHeaderView and a custom layout (you would probably need to implement an own grid layout, but it shouldn't be too hard).

budul
23rd November 2006, 10:10
Solution which works much better with 4.2 is to leave QTableWidget as Wysota advised. So QHeaderView + QGridLayout in QScrollArea works fine for horizonatl scrolling now. It is different with resizing columns (as table does) and hiding columns. It's not so fast as before and as one can see with use of QSplitter, but it's not big deal for me. Thanks anyway.

piotrek
23rd November 2006, 11:39
QStandardItemModel model(400, 200);

for (int row = 0; row < 400; ++row)
{
for (int column = 0; column < 200; ++column)
{
QModelIndex index = model.index(row, column, QModelIndex());
model.setData(index, QVariant((row+1) * (column+1)));
tableView.openPersistenEditor(index);
}
}


I'm thinking, that not all ist ok with setData. First parameter of this function is so called role. User should use as first index of data the Qt+UserRole (+0, +1, +2, ... ).

piotr