eelke created page: Model View

Eelke Klein 2018-08-26 08:30:50 +00:00
parent 73792009b7
commit e7c66f5bc0

16
Model-View.md Normal file

@ -0,0 +1,16 @@
The Model View system of Qt allows you to link a Model to a View but it is much more then that. This page describes how the pieces fit together.
What parts are there:
- The view ie QTableView
- The model, for instance a descendant of QAbstractTableModel
- QHeaderView, is responsible for the headers both above the columns and in front of rows
- QItemSelectionModel the view has a selection model
- QAbstractItemDelegate views use delegates to render items (on table can be set per row, column or globally)
You can get quite good results with just a view and a model. In this case the default delegate retrieves formatting info from the delegate. However formatting should be part of the view not the model.
# Ways to seperate formatting from the model
- We can use UserRoles to allow model to return what kind of data an item is (sometimes this can be deduced from the type stored in the variant but sometimes you might need more).
- We can go crazy with custom delegates and make sure the view is using the right delegate but that would mean that the view needs to be initialized with the right delegates and this might need to be updated when the model is changed.