继承者: QSqlQueryModel , QSqlTableModel , QSqlRelationalTableModel
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.
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.
当子类化 PySide.QtCore.QAbstractTableModel , you must implement PySide.QtCore.QAbstractItemModel.rowCount() , PySide.QtCore.QAbstractItemModel.columnCount() ,和 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() ,和 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 模型子类化参考 .
注意
另请参阅
模型类 PySide.QtCore.QAbstractItemModel PySide.QtCore.QAbstractListModel 像素器范例
| 参数: | parent – PySide.QtCore.QObject |
|---|
Constructs an abstract table model for the given parent .