PDA

View Full Version : QListView Refresh?



steve.bush
21st March 2011, 05:18
Hi,

I have a QListView and am adding elements to it from different classes, so I need to refresh it after all items are added.

How can I refresh it?

jerry7
21st March 2011, 05:31
you can emit dataChanged from model

steve.bush
21st March 2011, 06:07
you can emit dataChanged from model

Hi,

Can you give me an example? I checked the API Reference and it needs two parameters.

Doc: http://doc.qt.nokia.com/4.7/qlistview.html#dataChanged

I don't really have any parameters to pass...

wysota
21st March 2011, 09:14
I have a QListView and am adding elements to it from different classes, so I need to refresh it after all items are added.
Adding a new item to the view automatically schedules a refresh, you don't need to do anything.

steve.bush
21st March 2011, 20:46
Adding a new item to the view automatically schedules a refresh, you don't need to do anything.

I need to refresh it as I adding some elements from a different class and it looks like those are added and not appearing in the list. Hence, I want to do a refresh when the second class finishes execution.

So, back to my question. How can I refresh it. Can someone give me an example, because I do not have any parameters to pass..

wysota
21st March 2011, 21:37
I need to refresh it as I adding some elements from a different class and it looks like those are added and not appearing in the list.
It doesn't matter where you are adding the items from. If you can't see them then it means you are doing it wrong and refreshing will not help because the items are not there. If you are using a model approach, you need to add items according to rules that govern this architecture.

Telanis
14th February 2012, 19:38
It doesn't matter where you are adding the items from. If you can't see them then it means you are doing it wrong and refreshing will not help because the items are not there. If you are using a model approach, you need to add items according to rules that govern this architecture.

That was very helpful for steve.bush, I'm sure.

You need to make sure that the model knows to send the appropriate events. For example I have a model that uses a QStringList, and does this when I add an item:



beginInsertRows(QModelIndex(), items.size(), items.size());
stringList << newString;
endInsertRows();


And this when I clear all the items:



beginResetModel();
stringList.clear();
endResetModel();


The beginX() and endX() calls are important. If I leave them out when clearing the items, for example, the QListView only updates when focus changes (it's clicked on, or focus changes from the parent window to another window, etc.). When I wrap the clear operation with those calls, it's updated immediately.