Skip to content

PythonQt.Qt.QAbstractItemModel

QAbstractItemModel

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

The QAbstractItemModel class defines the standard interface that item models must use to be able to interoperate with other components in the model/view architecture. It is not supposed to be instantiated directly. Instead, you should subclass it to create new models.

The QAbstractItemModel class is one of the Model/View Classes and is part of Qt's model/view framework. It can be used as the underlying data model for the item view elements in QML or the item view classes in the Qt Widgets module.

If you need a model to use with an item view such as QML's List View element or the C++ widgets QListView or QTableView, you should consider subclassing QAbstractListModel or QAbstractTableModel instead of this class.

The underlying data model is exposed to views and delegates as a hierarchy of tables. If you do not make use of the hierarchy, then the model is a simple table of rows and columns. Each item has a unique index specified by a QModelIndex.

Every item of data that can be accessed via a model has an associated model index. You can obtain this model index using the index() function. Each index may have a sibling() index; child items have a parent() index.

Each item has a number of data elements associated with it and they can be retrieved by specifying a role (see Qt::ItemDataRole) to the model's data() function. Data for all available roles can be obtained at the same time using the itemData() function.

Data for each role is set using a particular Qt::ItemDataRole. Data for individual roles are set individually with setData(), or they can be set for all roles with setItemData().

Items can be queried with flags() (see Qt::ItemFlag) to see if they can be selected, dragged, or manipulated in other ways.

If an item has child objects, hasChildren() returns true for the corresponding index.

The model has a rowCount() and a columnCount() for each level of the hierarchy. Rows and columns can be inserted and removed with insertRows(), insertColumns(), removeRows(), and removeColumns().

The model emits signals to indicate changes. For example, dataChanged() is emitted whenever items of data made available by the model are changed. Changes to the headers supplied by the model cause headerDataChanged() to be emitted. If the structure of the underlying data changes, the model can emit layoutChanged() to indicate to any attached views that they should redisplay any items shown, taking the new structure into account.

The items available through the model can be searched for particular data using the match() function.

To sort the model, you can use sort().

Subclassing

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

When subclassing QAbstractItemModel, at the very least you must implement index(), parent(), rowCount(), columnCount(), and data(). These functions are used in all read-only models, and form the basis of editable models.

You can also reimplement hasChildren() to provide special behavior for models where the implementation of rowCount() is expensive. This makes it possible for models to restrict the amount of data requested by views, and can be used as a way to implement lazy population of model data.

To enable editing in your model, you must also implement setData(), and reimplement flags() to ensure that ItemIsEditable is returned. You can also reimplement headerData() and setHeaderData() to control the way the headers for your model are presented.

The dataChanged() and headerDataChanged() signals must be emitted explicitly when reimplementing the setData() and setHeaderData() functions, respectively.

Custom models need to create model indexes for other components to use. To do this, call createIndex() with suitable row and column numbers for the item, and an identifier for it, either as a pointer or as an integer value. The combination of these values must be unique for each item. Custom models typically use these unique identifiers in other reimplemented functions to retrieve item data and access information about the item's parents and children. See the Simple Tree Model Example for more information about unique identifiers.

It is not necessary to support every role defined in Qt::ItemDataRole. Depending on the type of data contained within a model, it may only be useful to implement the data() function to return valid information for some of the more common roles. Most models provide at least a textual representation of item data for the Qt::DisplayRole, and well-behaved models should also provide valid information for the Qt::ToolTipRole and Qt::WhatsThisRole. Supporting these roles enables models to be used with standard Qt views. However, for some models that handle highly-specialized data, it may be appropriate to provide data only for user-defined roles.

Models that provide interfaces to resizable data structures can provide implementations of insertRows(), removeRows(), insertColumns(),and removeColumns(). When implementing these functions, it is important to notify any connected views about changes to the model's dimensions both before and after they occur:

The private signals that these functions emit give attached components the chance to take action before any data becomes unavailable. The encapsulation of the insert and remove operations with these begin and end functions also enables the model to manage persistent model indexes correctly. If you want selections to be handled properly, you must ensure that you call these functions. If you insert or remove an item with children, you do not need to call these functions for the child items. In other words, the parent item will take care of its child items.

To create models that populate incrementally, you can reimplement fetchMore() and canFetchMore(). If the reimplementation of fetchMore() adds rows to the model, beginInsertRows() and endInsertRows() must be called.

Source: https://doc.qt.io/archives/qt-5.15/qabstractitemmodel.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
CheckIndexOption attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
DoNotUseParent attribute Any (shared captured text)
HorizontalSortHint attribute Any (shared captured text)
IndexIsValid attribute Any (shared captured text)
LayoutChangeHint attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
NoLayoutChangeHint attribute Any (shared captured text)
NoOption attribute Any (shared captured text)
ParentIsInvalid attribute Any (shared captured text)
VerticalSortHint attribute Any (shared captured text)
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
beginInsertColumns function (self, parent: Any, first: int, last: int) -> None X.beginInsertColumns(parent, first, last) (shared captured text)
beginInsertRows function (self, parent: Any, first: int, last: int) -> None X.beginInsertRows(parent, first, last) (shared captured text)
beginMoveColumns function (self, sourceParent: Any, sourceFirst: int, sourceLast: int, destinationParent: Any, destinationColumn: int) … X.beginMoveColumns(sourceParent, sourceFirst, sourceLast, destinationParent, destinationColumn) -> bool (shared captured text)
beginMoveRows function (self, sourceParent: Any, sourceFirst: int, sourceLast: int, destinationParent: Any, destinationRow: int) -> … X.beginMoveRows(sourceParent, sourceFirst, sourceLast, destinationParent, destinationRow) -> bool (shared captured text)
beginRemoveColumns function (self, parent: Any, first: int, last: int) -> None X.beginRemoveColumns(parent, first, last) (shared captured text)
beginRemoveRows function (self, parent: Any, first: int, last: int) -> None X.beginRemoveRows(parent, first, last) (shared captured text)
beginResetModel function (self) -> None Begins a model reset operation. (shared captured text)
blockSignals function (self, b: Any) -> bool X.blockSignals(b) -> bool (shared captured text)
buddy function (self, index: Any) -> Any X.buddy(index) -> PythonQt.QtCore.QModelIndex (shared captured text)
canDropMimeData function (self, data: Any, action: Any, row: int, column: int, parent: Any) -> bool X.canDropMimeData(data, action, row, column, parent) -> bool (shared captured text)
canFetchMore function (self, parent: Any) -> bool X.canFetchMore(parent) -> bool (shared captured text)
changePersistentIndex function (self, *args: Any, **kwargs: Any) -> None X.changePersistentIndex(from, to) (shared captured text)
changePersistentIndexList function (self, *args: Any, **kwargs: Any) -> None X.changePersistentIndexList(from, to) (shared captured text)
childEvent function (self, event: Any) -> Any (shared captured text)
children function (self) -> tuple X.children() -> tuple (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
columnCount function (self, parent: Any) -> int X.columnCount(parent) -> int (shared captured text)
columnsAboutToBeInserted function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.columnsAboutToBeInserted; argument details are not documented.
columnsAboutToBeMoved function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.columnsAboutToBeMoved; argument details are not documented.
columnsAboutToBeRemoved function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.columnsAboutToBeRemoved; argument details are not documented.
columnsInserted function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.columnsInserted; argument details are not documented.
columnsMoved function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.columnsMoved; argument details are not documented.
columnsRemoved function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.columnsRemoved; argument details are not documented.
connect function (self, signal: Any, receiver: Any, slot: Any, type: Any) -> bool X.connect(signal, receiver, slot, type) -> bool (shared captured text)
createIndex function (self, row: int, column: int, id: Any) -> Any X.createIndex(row, column, id) -> PythonQt.QtCore.QModelIndex (shared captured text)
customEvent function (self, event: Any) -> Any (shared captured text)
data function (self, index: Any, role: int) -> Any X.data(index, role) -> object (shared captured text)
dataChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.dataChanged; argument details are not documented.
decodeData function (self, row: int, column: int, parent: Any, stream: Any) -> bool X.decodeData(row, column, parent, stream) -> bool (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
deleteLater function (self) -> Any (shared captured text)
destroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.destroyed; argument details are not documented.
disconnect function (self, signal: Any, receiver: Any, slot: Any) -> bool X.disconnect(signal, receiver, slot) -> bool (shared captured text)
dropMimeData function (self, data: Any, action: Any, row: int, column: int, parent: Any) -> bool X.dropMimeData(data, action, row, column, parent) -> bool (shared captured text)
dumpObjectInfo function (self) -> Any (shared captured text)
dumpObjectTree function (self) -> Any (shared captured text)
dynamicPropertyNames function (self) -> Any (shared captured text)
encodeData function (self, indexes: Any, stream: Any) -> None X.encodeData(indexes, stream) (shared captured text)
endInsertColumns function (self) -> None Ends a column insertion operation. (shared captured text)
endInsertRows function (self) -> None Ends a row insertion operation. (shared captured text)
endMoveColumns function (self) -> None Ends a column move operation. (shared captured text)
endMoveRows function (self) -> None Ends a row move operation. (shared captured text)
endRemoveColumns function (self) -> None Ends a column removal operation. (shared captured text)
endRemoveRows function (self) -> None Ends a row removal operation. (shared captured text)
endResetModel function (self) -> None Completes a model reset operation. (shared captured text)
event function (self, event: Any) -> bool X.event(event) -> bool (shared captured text)
eventFilter function (self, watched: Any, event: Any) -> bool X.eventFilter(watched, event) -> bool (shared captured text)
fetchMore function (self, parent: Any) -> None Fetches any available data for the items with the parent specified by the parent index. (shared captured text)
findChild function (self, type: Any, name: Any) -> Any X.findChild(type, name) -> PythonQt.private.QObject (shared captured text)
findChildren function (self, type: Any, name: Any) -> tuple X.findChildren(type, name) -> tuple (shared captured text)
flags function (self, index: Any) -> Any Returns the item flags for the given index. (shared captured text)
hasChildren function (self, parent: Any) -> bool X.hasChildren(parent) -> bool (shared captured text)
hasIndex function (self, row: int, column: int, parent: Any) -> bool X.hasIndex(row, column, parent) -> bool (shared captured text)
headerData function (self, section: int, orientation: Any, role: int) -> Any X.headerData(section, orientation, role) -> object (shared captured text)
headerDataChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.headerDataChanged; argument details are not documented.
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
index function (self, row: int, column: int, parent: Any) -> Any X.index(row, column, parent) -> PythonQt.QtCore.QModelIndex (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
insertColumn function (self, column: int, parent: Any) -> bool X.insertColumn(column, parent) -> bool (shared captured text)
insertColumns function (self, column: int, count: int, parent: Any) -> bool X.insertColumns(column, count, parent) -> bool (shared captured text)
insertRow function (self, row: int, parent: Any) -> bool X.insertRow(row, parent) -> bool (shared captured text)
insertRows function (self, row: int, count: int, parent: Any) -> bool X.insertRows(row, count, parent) -> bool (shared captured text)
installEventFilter function (self, filterObj: Any) -> Any (shared captured text)
isSignalConnected function (self, signal: Any) -> bool X.isSignalConnected(signal) -> bool (shared captured text)
isWidgetType function (self) -> bool X.isWidgetType() -> bool (shared captured text)
isWindowType function (self) -> bool X.isWindowType() -> bool (shared captured text)
itemData function (self, index: Any) -> dict X.itemData(index) -> dict (shared captured text)
killTimer function (self, id: Any) -> Any (shared captured text)
layoutAboutToBeChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.layoutAboutToBeChanged; argument details are not documented.
layoutChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.layoutChanged; argument details are not documented.
match function (self, start: Any, role: int, value: Any, hits: int, arg4: flags) -> tuple X.match(start, role, value, hits, flags) -> tuple (shared captured text)
metaObject function (self) -> Any X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text)
mimeData function (self, indexes: Any) -> Any X.mimeData(indexes) -> PythonQt.QtCore.QMimeData (shared captured text)
mimeTypes function (self) -> tuple X.mimeTypes() -> tuple (shared captured text)
modelAboutToBeReset function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.modelAboutToBeReset; argument details are not documented.
modelReset function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.modelReset; argument details are not documented.
moveColumn function (self, sourceParent: Any, sourceColumn: int, destinationParent: Any, destinationChild: int) -> bool X.moveColumn(sourceParent, sourceColumn, destinationParent, destinationChild) -> bool (shared captured text)
moveColumns function (self, sourceParent: Any, sourceColumn: int, count: int, destinationParent: Any, destinationChild: int) -> bo… X.moveColumns(sourceParent, sourceColumn, count, destinationParent, destinationChild) -> bool (shared captured text)
moveRow function (self, sourceParent: Any, sourceRow: int, destinationParent: Any, destinationChild: int) -> bool X.moveRow(sourceParent, sourceRow, destinationParent, destinationChild) -> bool (shared captured text)
moveRows function (self, sourceParent: Any, sourceRow: int, count: int, destinationParent: Any, destinationChild: int) -> bool X.moveRows(sourceParent, sourceRow, count, destinationParent, destinationChild) -> bool (shared captured text)
moveToThread function (self, thread: Any) -> Any (shared captured text)
objectName attribute Any (shared captured text)
objectNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.objectNameChanged; argument details are not documented.
parent function (self, child: Any) -> Any X.parent(child) -> PythonQt.QtCore.QModelIndex (shared captured text)
persistentIndexList function (self) -> tuple X.persistentIndexList() -> tuple (shared captured text)
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
removeColumn function (self, column: int, parent: Any) -> bool X.removeColumn(column, parent) -> bool (shared captured text)
removeColumns function (self, column: int, count: int, parent: Any) -> bool X.removeColumns(column, count, parent) -> bool (shared captured text)
removeEventFilter function (self, obj: Any) -> Any (shared captured text)
removeRow function (self, row: int, parent: Any) -> bool X.removeRow(row, parent) -> bool (shared captured text)
removeRows function (self, row: int, count: int, parent: Any) -> bool X.removeRows(row, count, parent) -> bool (shared captured text)
revert function (self) -> None Lets the model know that it should discard cached information. (shared captured text)
roleNames function (self) -> dict X.roleNames() -> dict (shared captured text)
rowCount function (self, parent: Any) -> int X.rowCount(parent) -> int (shared captured text)
rowsAboutToBeInserted function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.rowsAboutToBeInserted; argument details are not documented.
rowsAboutToBeMoved function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.rowsAboutToBeMoved; argument details are not documented.
rowsAboutToBeRemoved function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.rowsAboutToBeRemoved; argument details are not documented.
rowsInserted function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.rowsInserted; argument details are not documented.
rowsMoved function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.rowsMoved; argument details are not documented.
rowsRemoved function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QAbstractItemModel.rowsRemoved; argument details are not documented.
sender function (self) -> Any X.sender() -> PythonQt.private.QObject (shared captured text)
senderSignalIndex function (self) -> int X.senderSignalIndex() -> int (shared captured text)
setData function (self, index: Any, value: Any, role: int) -> bool X.setData(index, value, role) -> bool (shared captured text)
setHeaderData function (self, section: int, orientation: Any, value: Any, role: int) -> bool X.setHeaderData(section, orientation, value, role) -> bool (shared captured text)
setItemData function (self, index: Any, roles: Any) -> bool X.setItemData(index, roles) -> bool (shared captured text)
setObjectName function (self, name: Any) -> Any (shared captured text)
setParent function (self, parent: Any) -> Any (shared captured text)
setProperty function (self, name: Any, value: Any) -> bool X.setProperty(name, value) -> bool (shared captured text)
sibling function (self, row: int, column: int, idx: Any) -> Any X.sibling(row, column, idx) -> PythonQt.QtCore.QModelIndex (shared captured text)
signalsBlocked function (self) -> bool X.signalsBlocked() -> bool (shared captured text)
sort function (self, column: int, order: Any) -> None X.sort(column, order) (shared captured text)
span function (self, index: Any) -> Any X.span(index) -> PythonQt.QtCore.QSize (shared captured text)
startTimer function (self, interval: Any, timerType: Any) -> int X.startTimer(interval, timerType) -> int (shared captured text)
submit function (self) -> bool X.submit() -> bool (shared captured text)
supportedDragActions function (self) -> Any Returns the actions supported by the data in this model. (shared captured text)
supportedDropActions function (self) -> Any Returns the drop actions supported by this model. (shared captured text)
thread function (self) -> Any (shared captured text)
timerEvent function (self, event: Any) -> Any (shared captured text)
tr function (self, text: Any, ambig: Any, n: Any) -> str X.tr(text, ambig, n) -> str (shared captured text)