View Full Version : QListView updating dynamically on demand / alternative data storage

11th October 2009, 00:28
I have a big structure which contains lots of information. This structure can be in excess of a million items in size.

How does QListView handle having > 1 million items?

Since I have all the data I want to display already, is it possible to subclass the control so I can read my own structure to find out what to display rather than using 'insert' and QListviews own data storage? Just seems like a waste of memory to duplicate a lot of stuff.

11th October 2009, 08:42
The best thing is to write your own model if the standard models didn't fit your needs. Then Qt has absolutely no problem with more than 1 million items because it only fetches a few of them to display. So it saves memory. And then it fetches more if needed...

11th October 2009, 10:49
Brilliant, thanks. I knew it was possible, but didn't know what it was called.

11th October 2009, 11:00
but didn't know what it was called.

It's called Model/View Programming and it is very very good documented at the docs: http://doc.trolltech.com/4.5/model-view-programming.html.
Maybe it is enough for you using a standard model but with a custom delegate for displaying the data.

12th October 2009, 01:06
Its fine to read the docs, but until you know what your looking for, its kinda difficult. I don't read the docs like a book and just jump to the pages of interest.

I looked up the model programming and seemed quite easy. I threw together a class and assigned it to the widget. Works brilliant, just as I wanted it to. However, I would be interested to know how the widget knows if some data is changed. For example, if the widget is showing items 1 - 30 on a screen, and then the data for item 10 changes in the background, how does the widget know to redraw?

Don't know if a delegate would work as I need control over the row count. I will require painting later on though as I'll need to change the font color of some items. Is this a good use of delegate? I was thinking of overriding the paint method, but not checked if thats possible yet.

12th October 2009, 11:05
There is a signal dataChanged(QModelIndex, QModelIndex) in every model implementation and be sure when implementing your own mode to emit this signal everytime that some data chenges in background - this would notify view about need to redraw changed indexes (indices?).