Inherited by: QSqlQueryModel, QSqlTableModel, QSqlRelationalTableModel
The PySide.QtCore.QAbstractTableModel class provides an abstract model that can be subclassed to create table models.
PySide.QtCore.QAbstractTableModel provides a standard interface for models that represent their data as a two-dimensional array of items. It is not used directly, but must be subclassed.
Since the model provides a more specialized interface than PySide.QtCore.QAbstractItemModel , it is not suitable for use with tree views, although it can be used to provide data to a PySide.QtGui.QListView . If you need to represent a simple list of items, and only need a model to contain a single column of data, subclassing the PySide.QtCore.QAbstractListModel may be more appropriate.
The PySide.QtCore.QAbstractItemModel.rowCount() and PySide.QtCore.QAbstractItemModel.columnCount() functions return the dimensions of the table. To retrieve a model index corresponding to an item in the model, use PySide.QtCore.QAbstractTableModel.index() and provide only the row and column numbers.
When subclassing PySide.QtCore.QAbstractTableModel , you must implement PySide.QtCore.QAbstractItemModel.rowCount() , PySide.QtCore.QAbstractItemModel.columnCount() , and PySide.QtCore.QAbstractItemModel.data() . Default implementations of the PySide.QtCore.QAbstractTableModel.index() and PySide.QtCore.QAbstractTableModel.parent() functions are provided by PySide.QtCore.QAbstractTableModel . Well behaved models will also implement PySide.QtCore.QAbstractItemModel.headerData() .
Editable models need to implement PySide.QtCore.QAbstractItemModel.setData() , and implement PySide.QtCore.QAbstractItemModel.flags() to return a value containing Qt.ItemIsEditable .
Models that provide interfaces to resizable data structures can provide implementations of PySide.QtCore.QAbstractItemModel.insertRows() , PySide.QtCore.QAbstractItemModel.removeRows() , PySide.QtCore.QAbstractItemModel.insertColumns() , and PySide.QtCore.QAbstractItemModel.removeColumns() . When implementing these functions, it is important to call the appropriate functions so that all connected views are aware of any changes:
- An PySide.QtCore.QAbstractItemModel.insertRows() implementation must call PySide.QtCore.QAbstractItemModel.beginInsertRows() before inserting new rows into the data structure, and it must call PySide.QtCore.QAbstractItemModel.endInsertRows() immediately afterwards.
- An PySide.QtCore.QAbstractItemModel.insertColumns() implementation must call PySide.QtCore.QAbstractItemModel.beginInsertColumns() before inserting new columns into the data structure, and it must call PySide.QtCore.QAbstractItemModel.endInsertColumns() immediately afterwards.
- A PySide.QtCore.QAbstractItemModel.removeRows() implementation must call PySide.QtCore.QAbstractItemModel.beginRemoveRows() before the rows are removed from the data structure, and it must call PySide.QtCore.QAbstractItemModel.endRemoveRows() immediately afterwards.
- A PySide.QtCore.QAbstractItemModel.removeColumns() implementation must call PySide.QtCore.QAbstractItemModel.beginRemoveColumns() before the columns are removed from the data structure, and it must call PySide.QtCore.QAbstractItemModel.endRemoveColumns() immediately afterwards.
Note
Some general guidelines for subclassing models are available in the Model Subclassing Reference .
Note
See also
Model Classes PySide.QtCore.QAbstractItemModel PySide.QtCore.QAbstractListModel Pixelator Example
Parameters: | parent – PySide.QtCore.QObject |
---|
Constructs an abstract table model for the given parent .