|  | Home · All Classes · Modules

# QProxyModel Class Reference
[QtGui module]

The QProxyModel class provides support for processing data passed between another model and a view. More...

Inherits QAbstractItemModel.

### Methods

- __init__ (self, QObject parent = None)
- int columnCount (self, QModelIndex parent)
- QVariant data (self, QModelIndex index, int role)
- bool dropMimeData (self, QMimeData data, Qt.DropAction action, int row, int column, QModelIndex parent)
- fetchMore (self, QModelIndex parent)
- Qt.ItemFlags flags (self, QModelIndex index)
- bool hasChildren (self, QModelIndex parent)
- QVariant headerData (self, int section, Qt.Orientation orientation, int role)
- QModelIndex index (self, int row, int column, QModelIndex parent)
- bool insertColumns (self, int column, int count, QModelIndex parent)
- bool insertRows (self, int row, int count, QModelIndex parent)
- QModelIndex-list match (self, QModelIndex start, int role, QVariant value, int hits, Qt.MatchFlags flags)
- QMimeData mimeData (self, QModelIndex-list indexes)
- QStringList mimeTypes (self)
- QAbstractItemModel model (self)
- QModelIndex parent (self, QModelIndex child)
- QObject parent (self)
- revert (self)
- int rowCount (self, QModelIndex parent)
- bool setData (self, QModelIndex index, QVariant value, int role)
- bool setHeaderData (self, int section, Qt.Orientation orientation, QVariant value, int role)
- setModel (self, QAbstractItemModel model)
- sort (self, int column, Qt.SortOrder order)
- QSize span (self, QModelIndex index)
- bool submit (self)
- Qt.DropActions supportedDropActions (self)

## Detailed Description

The QProxyModel class provides support for processing data passed between another model and a view.

If you want to do filtering and sorting, see QSortFilterProxyModel.

Proxy models provide a standard model interface that can be used to manipulate the data retrieved through an underlying model. They can be used to perform operations such as sorting and filtering on the data obtained without changing the contents of the model.

Just as with subclasses of QAbstractItemView, QProxyModel provides the setModel() function that is used to specify the model to be acted on by the proxy. Views can be connected to either the underlying model or the proxy model with QAbstractItemView.setModel().

Since views rely on the information provided in model indexes to identify items of data from models, and to position these items in some visual representation, proxy models must create their own model indexes instead of supplying model indexes from their underlying models.

See also Model/View Programming and QAbstractItemModel.

## Method Documentation

### QProxyModel.__init__ (self, QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a proxy model with the given parent.

### int QProxyModel.columnCount (self, QModelIndex parent)

Returns the number of columns for the given parent.

Reimplemented from QAbstractItemModel.

See also QAbstractItemModel.columnCount().

### QVariant QProxyModel.data (self, QModelIndex index, int role)

Returns the data stored in the item with the given index under the specified role.

Reimplemented from QAbstractItemModel.

See also setData().

### bool QProxyModel.dropMimeData (self, QMimeData data, Qt.DropAction action, int row, int column, QModelIndex parent)

Returns true if the model accepts the data dropped onto an attached view for the specified action; otherwise returns false.

The parent, row, and column details can be used to control which MIME types are acceptable to different parts of a model when received via the drag and drop system.

Reimplemented from QAbstractItemModel.

### QProxyModel.fetchMore (self, QModelIndex parent)

Fetches more child items of the given parent. This function is used by views to tell the model that they can display more data than the model has provided.

Reimplemented from QAbstractItemModel.

See also QAbstractItemModel.fetchMore().

### Qt.ItemFlags QProxyModel.flags (self, QModelIndex index)

Returns the item flags for the given index.

Reimplemented from QAbstractItemModel.

### bool QProxyModel.hasChildren (self, QModelIndex parent)

Returns true if the item corresponding to the parent index has child items; otherwise returns false.

Reimplemented from QAbstractItemModel.

See also QAbstractItemModel.hasChildren().

### QVariant QProxyModel.headerData (self, int section, Qt.Orientation orientation, int role)

Returns the data stored in the section of the header with specified orientation under the given role.

Reimplemented from QAbstractItemModel.

See also setHeaderData().

### QModelIndex QProxyModel.index (self, int row, int column, QModelIndex parent)

Returns the model index with the given row, column, and parent.

Reimplemented from QAbstractItemModel.

See also QAbstractItemModel.index().

### bool QProxyModel.insertColumns (self, int column, int count, QModelIndex parent)

Inserts count columns into the model, creating new items as children of the given parent. The new columns are inserted before the column specified. If the parent item has no children, a single row is created to contain the required number of columns.

Returns true if the columns were successfully inserted; otherwise returns false.

Reimplemented from QAbstractItemModel.

See also QAbstractItemModel.insertColumns().

### bool QProxyModel.insertRows (self, int row, int count, QModelIndex parent)

Inserts count rows into the model, creating new items as children of the given parent. The new rows are inserted before the row specified. If the parent item has no children, a single column is created to contain the required number of rows.

Returns true if the rows were successfully inserted; otherwise returns false.

Reimplemented from QAbstractItemModel.

See also QAbstractItemModel.insertRows().

### QModelIndex-list QProxyModel.match (self, QModelIndex start, int role, QVariant value, int hits, Qt.MatchFlags flags)

Returns a list of model indexes that each contain the given value for the role specified. The search begins at the start index and is performed according to the specified flags. The search continues until the number of matching data items equals hits, the last row is reached, or the search reaches start again, depending on whether `MatchWrap` is specified in flags.

Reimplemented from QAbstractItemModel.

See also QAbstractItemModel.match().

### QMimeData QProxyModel.mimeData (self, QModelIndex-list indexes)

The QMimeData result

Returns MIME data for the specified indexes in the model.

Reimplemented from QAbstractItemModel.

### QStringList QProxyModel.mimeTypes (self)

Returns a list of MIME types that are supported by the model.

Reimplemented from QAbstractItemModel.

### QAbstractItemModel QProxyModel.model (self)

Returns the model that contains the data that is available through the proxy model.

See also setModel().

### QModelIndex QProxyModel.parent (self, QModelIndex child)

Returns the model index that corresponds to the parent of the given child index.

Reimplemented from QAbstractItemModel.

### QObject QProxyModel.parent (self)

### QProxyModel.revert (self)

Reimplemented from QAbstractItemModel.

### int QProxyModel.rowCount (self, QModelIndex parent)

Returns the number of rows for the given parent.

Reimplemented from QAbstractItemModel.

See also QAbstractItemModel.rowCount().

### bool QProxyModel.setData (self, QModelIndex index, QVariant value, int role)

Sets the role data for the item at index to value. Returns true if successful; otherwise returns false.

The base class implementation returns false. This function and data() must be reimplemented for editable models.

Reimplemented from QAbstractItemModel.

See also data(), itemData(), and QAbstractItemModel.setData().

### bool QProxyModel.setHeaderData (self, int section, Qt.Orientation orientation, QVariant value, int role)

Sets the role data in the section of the header with the specified orientation to the value given.

Reimplemented from QAbstractItemModel.

See also headerData() and QAbstractItemModel.setHeaderData().

### QProxyModel.setModel (self, QAbstractItemModel model)

Sets the given model to be processed by the proxy model.

See also model().

### QProxyModel.sort (self, int column, Qt.SortOrder order)

Sorts the child items in the specified column according to the sort order defined by order.

Reimplemented from QAbstractItemModel.

See also QAbstractItemModel.sort().

### QSize QProxyModel.span (self, QModelIndex index)

Returns the size of the item that corresponds to the specified index.

Reimplemented from QAbstractItemModel.

### bool QProxyModel.submit (self)

Reimplemented from QAbstractItemModel.

### Qt.DropActions QProxyModel.supportedDropActions (self)

Returns the drop actions that are supported by the model; this is a combination of the individual actions defined in Qt.DropActions.

The selection of drop actions provided by the model will influence the behavior of the component that started the drag and drop operation.

Reimplemented from QAbstractItemModel.

See also Drag and Drop.