Table Of Contents

Previous topic


Next topic



Inherited by: QSqlQueryModel, QSqlTableModel, QSqlRelationalTableModel

Detailed Description

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 . 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:


Some general guidelines for subclassing models are available in the Model Subclassing Reference .


See also

Model Classes PySide.QtCore.QAbstractItemModel PySide.QtCore.QAbstractListModel Pixelator Example

class PySide.QtCore.QAbstractTableModel([parent=None])

Constructs an abstract table model for the given parent .