Search code examples
qtlistviewqmlqt5qabstractlistmodel

Does the ListView redraw the underlaying model if the model changes?


The question is basically the title, but some more detail:

I have subclassed the QAbstractListModel, lets name it myModel. I am creating the content of myModel in c++ code, then feeding it into a ListView in QML. My code modifies myModel in C++ code and I can see the modifications right away in my ListView, which is fine. My question is, that does the ListView redraws all of its elements, when the underlaying model changes (like adding an item) or just draws the new item?


Solution

  • Under the ListView delegate I have checked how many times does Component.onCompleted and Component.onDestruction called. The results are, that when a new item is inserted the Component.onCompleted is called only once and when an item is removed the Component.onDestruction is called only once, which means that ListView doesn't redraw the whole list when inserting and removing items!