Correct way of binding Model data to Views and update the latter

286 Views Asked by At

I'm working with Python+Qt (PyQt5) for few time and I was wondering what is the most efficient (and correct) way to bind the Model structure (let say a List of objects) to a View representation (let say QListWidgets) so as to achieve safe and efficient updating of the latter when the former is modified (added/deleted/modified elements). I was thinking of different strategies, such as:

  • Subclassing List object to implement a on_change method in the Model that ask for an update in the View
  • Use another type of structure that implement the above
  • Just hard-calling the View update each time I'm processing Model data updates

Are there any suggestion? I'd like to highlight that "List[MyObject] vs. QWidgetList" is just the topic I'm currently working on, but my question is meant to be as much general as possible.

EDIT

Thanks to @BrenBarn and @musicamante I came acress Model/View architecture so that the inheritance of QAbstractListModel helps easily handle the structure data below a QListView. The very only drawback is that each time the model is update (inserting/deletion/editing), a manual emission of QAbstractListModel.dataChanged signal is to be performed

0

There are 0 best solutions below