class QIdentityProxyModel

The QIdentityProxyModel class proxies its source model unmodified. More

Inheritance diagram of PySide6.QtCore.QIdentityProxyModel

Synopsis

Methods

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

QIdentityProxyModel can be used to forward the structure of a source model exactly, with no sorting, filtering or other transformation. This is similar in concept to an identity matrix where A.I = A.

Because it does no sorting or filtering, this class is most suitable to proxy models which transform the data() of the source model. For example, a proxy model could be created to define the font used, or the background colour, or the tooltip etc. This removes the need to implement all data handling in the same class that creates the structure of the model, and can also be used to create re-usable components.

This also provides a way to change the data in the case where a source model is supplied by a third party which cannot be modified.

class DateFormatProxyModel(QIdentityProxyModel):

  # ...
  def setDateFormatString(formatString):

    m_formatString = formatString

  QVariant data(QModelIndex index, int role) override

    if role != Qt.DisplayRole:
      return QIdentityProxyModel.data(index, role)
    dateTime = sourceModel().data(SourceClass::DateRole).toDateTime()
    return dateTime.toString(m_formatString)

  QMap<int, QVariant> itemData(QModelIndex proxyIndex) override

      QVariant> map = QIdentityProxyModel.itemData(proxyIndex)
      map[Qt.DisplayRole] = data(proxyIndex)
      return map

# private
  m_formatString = QString()
__init__([parent=None])
Parameters:

parentQObject

Constructs an identity model with the given parent.

handleSourceDataChanges()
Return type:

bool

Returns true if this proxy model handles the source model data changes, otherwise returns false.

handleSourceLayoutChanges()
Return type:

bool

Returns true if this proxy model handles the source model layout changes, otherwise returns false.

setHandleSourceDataChanges(arg__1)
Parameters:

arg__1 – bool

If b is true, this proxy model will handle the source model data changes (by connecting to QAbstractItemModel::dataChanged signal).

The default is for this proxy model to handle the source model data changes.

In sub-classes of QIdentityProxyModel , it may be useful to set this to false if you need to specially handle the source model data changes.

Note

Calling this method will only have an effect after calling setSourceModel() .

setHandleSourceLayoutChanges(arg__1)
Parameters:

arg__1 – bool

If b is true, this proxy model will handle the source model layout changes (by connecting to QAbstractItemModel::layoutAboutToBeChanged and QAbstractItemModel::layoutChanged signals).

The default is for this proxy model to handle the source model layout changes.

In sub-classes of QIdentityProxyModel , it may be useful to set this to false if you need to specially handle the source model layout changes.

Note

Calling this method will only have an effect after calling setSourceModel() .