How to make a listview with sections dynamic?
-
Hi there, I'm working with QML/Qt5/Python and I have a listview of clients with several properties. For the sake of this post, a client has an 'email' and a 'connected status' as properties which may change any time. In my listview I have sections and the user can change the sections from email to connected status as they need.
These properties can change at any time while the app is being used. So the changes come in asynchronously and the list needs to adjust as the list changes no matter what property is being sectioned on.
My problem is that QML doesn't sort the list view model, so if there are 10 'connected' clients and 10 'disconnected' clients in the model and the bottom one connects, as far as I understand it is up to me to sort the list to suit the current section settings.
How is this done in a smooth way? The list view model itself doesn't provide a nice sort function, so the best way I could think of to do it is to loop on the model and append everything to a javascript array, use the array.sort(sort function) on the correct property, clear the model and loop on the array and append back into the model. But it happens frequently and rebuilding the model interrupts the user while they are scrolling through it and puts the list back at the top.
Is there a better way to do this? Thanks.