PDA

View Full Version : Updating QStandardItemModel model which is set to view takes long time



padma
20th March 2017, 21:48
Hello,

I currently have two grids, one at the top and one at the bottom.
I have fifty rows in the bottom grid, and 'n' rows in the top grid.
On clicking "Add rows" button, I need to add the 50 rows in the bottom grid to the top grid, and color the newly added rows.
Then, I need to remove all rows in the bottom grid.

I am using QStandardItemModel as the source model for the two grids.

I tried using "insertrow" from the qstandarditemmodel, to pass qstandarditem values obtained from the second grid, to the function.
It still takes about one second, for as less as 50 rows to update an existing model with new rows.

Is there a way to do this quickly?

Thanks,
Padma

Santosh Reddy
21st March 2017, 05:08
How are you moving the item between the models ?

Are you just removing and inserting the rows ?

or

using takeItem() and insertItem() ? This is relatively faster than other method.

padma
21st March 2017, 19:54
I modified the code based on your recommendation:

I used 'takeItem' and added the QStandardItem to a list with row items.
Then I take this list and use 'InsertRow' to insert it into the top grid.
I couldnt find 'insertItem' for qstandarditemmodel.. I found that 'setItem' takes way too much time, when editing a model that has already been set to the view..

It is now at about 0.86, slightly better.

I am still not sure as to why it would take as much time, when loading 100+ rows initially into the grid is almost instantaneous..

Santosh Reddy
22nd March 2017, 04:51
QStandardItemModel and QStandardItem are out of box solutions for table view, which may not give efficient results with large data sets, as internally QStandardItemModel needs to many house keeping stuff, which may be a overhead and may not be required for your application.

If performance and response is important for your application then better implement a custom model, which will be a bit complicated than using StandardItemModel but it all depends on your application data model.