Solved Does QTableView call only on QAbstractTableModel's virtual functions when it needs to display data?
-
In "2.4 Setting up Headers for Columns and Rows" in the Qt5.7 Model View tutorial, the file "mymodel.cpp" has 4 virtual functions for the class
MyModel: QAbstractTableModel
:rowCount
,columnCount
,data
, andheaderData
. I'm noticing that all these functions return data that is displayed by the QTableViewview
. Does that mean Qt views (likeQTableView
) communicate with Qt models by using virtual functions from the Qt models (like models ofQAbstractItemModel
andQAbstractTableModel
)? I'm pretty sure that's how models and views work, I just want to make sure I'm getting it right. -
Hi,
Not all methods are virtual. QAbstractItemModel provides the foundation to build your own custom models and you'll have to re-implement parts of the virtual methods in order to make it work the way you want it.
-
That helps clear some confusion, thanks.
-
To clarify, that is an interface i.e. if you implement a View you should only rely on methods and signals defined in QAbstractItemModel so your view will work with all models implementing that interface correctly. QAbstractItemModel is the bridge between model and view (and delegate)