Details
-
Suggestion
-
Resolution: Unresolved
-
P2: Important
-
None
-
None
-
None
Description
Suppose you are a user that wants to subclass QAbstractItemModel, and you want to do the most basic thing: add the underlying data that the model uses. You go to https://doc.qt.io/qt-6/qabstractitemmodel.html. In order, you see:
- https://doc.qt.io/qt-6/qabstractitemmodel.html#details - if you read far enough, it shows which functions are needed: insertRows(). However, that has no example: https://doc.qt.io/qt-6/qabstractitemmodel.html#insertRows.
- https://doc.qt.io/qt-6/qabstractitemmodel.html#subclassing - another bunch of overview text that, again, describes which functions to use but provides no code examples.
- See also Model Classes, Model Subclassing Reference, QModelIndex, QAbstractItemView, Using drag and drop with item views, Simple DOM Model Example, Simple Tree Model Example, Editable Tree Model Example, and Fetch More Example - surprisingly not a single one of the examples listed here shows how to implement a simple list model. They are all trees, or e.g. use QListWidget. https://doc.qt.io/qt-6/qtwidgets-itemviews-fetchmore-example.html comes close but is QAbstractListModel, and is more complex than is necessary to implement a simple list model, since it is focused on fetching.
- If you get this far, there are some related examples listed on https://doc.qt.io/qt-6/model-view-programming.html#related-examples. These are also tree or table models.
- If you start fishing around the example directories, the ones you find in https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/itemviews are also either widgets-view-specific or e.g. table models.
We need a simple example that explains how to subclass QAbstractItemModel and add item to display it as a list, preferably in Qt Widgets and Quick (so, separate examples).
Attachments
Issue Links
- relates to
-
QTBUG-68100 idea: QAbstractItemModel code generator or wizard
- Reported
-
QTBUG-94505 QAbstractItemModel has no API to add data to the model
- Reported