PDA

View Full Version : QAbstractItemModel or QStandardItemModel



chithara
9th April 2019, 15:46
Hi,

I have a class with huge number of data members in it out of which few members should be shown up as Tree format and other few members should be used as table format. I am sure that I should be going for Model-View Architecture (QTreeView and QTableView). My question here is which model should I prefer? A class subclassing QAbstractItemModel or a class subclassing QStandardItemModel ? What is the difference and when /why I prefer over one another?

anda_skoa
10th April 2019, 07:05
QStandardItemModel is usually not being used as a base class.

Its main purpose is to have a ready-to-go model that contains data rather than provides access to already existing data.
E.g. when you have data that is just displayed but isn't needed elsewhere, then you can simply create QStandardItem objects with that data and use these to forma list, table or tree.

Creating a custom model, e.g. a table based on QAbstractTableModel, is more work, but allows to access data that already exists in some form elsewhere.

Sometimes the QStandardItemModel is also used as an intermediate step, as it is faster to get something to show up than implementing a custom model, especially tree models.

Cheers,
_

chithara
11th April 2019, 06:06
Do i really need to go for QStandardItemModel() for QTreeView? What if my data(to be shown in QTreeView) is large in number?

anda_skoa
11th April 2019, 08:04
Do i really need to go for QStandardItemModel() for QTreeView?

Why would you need to do that?



What if my data(to be shown in QTreeView) is large in number?

Then you would most likely implement a custom tree model, deriving from QAbstractItemModel

Cheers,
_

chithara
10th May 2019, 06:50
Implemented own custom tree model from QAbstractItemModel (followed Qt example SimpleTreeModel)
Thank you