|  | Home · All Classes · Main Classes · Annotated · Grouped Classes · Functions |

# QStandardItemModel Class Reference

The QStandardItemModel class provides a generic model for storing custom data. More...

    #include <QStandardItemModel>

Part of the QtGui module.

Inherits QAbstractItemModel.

- List of all members, including inherited members

### Public Functions

- QStandardItemModel ( QObject * parent = 0 )
- QStandardItemModel ( int rows, int columns, QObject * parent = 0 )
- ~QStandardItemModel ()
- void clear ()
- virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const
- virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const
- virtual Qt::ItemFlags flags ( const QModelIndex & index ) const
- virtual bool hasChildren ( const QModelIndex & parent = QModelIndex() ) const
- virtual QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const
- virtual bool insertColumns ( int column, int count, const QModelIndex & parent = QModelIndex() )
- virtual bool insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() )
- virtual QModelIndex parent ( const QModelIndex & child ) const
- virtual bool removeColumns ( int column, int count, const QModelIndex & parent = QModelIndex() )
- virtual bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() )
- virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const
- virtual bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole )

- 32 public functions inherited from QAbstractItemModel
- 28 public functions inherited from QObject

### Additional Inherited Members

- 1 property inherited from QObject
- 2 public slots inherited from QAbstractItemModel
- 1 public slot inherited from QObject
- 3 signals inherited from QAbstractItemModel
- 1 signal inherited from QObject
- 4 static public members inherited from QObject
- 12 protected functions inherited from QAbstractItemModel
- 7 protected functions inherited from QObject

## Detailed Description

The QStandardItemModel class provides a generic model for storing custom data.

QStandardItemModel provides a model that that can be used as a repository for standard Qt data types. Data is written to the model and read back using the standard QAbstractItemModel interface. The way each item of information is referenced depends on how the data is inserted into the model.

For performance and flexibility, you may want to subclass QAbstractItemModel to provide support for different kinds of repositories. For example, the QDirModel provides a model interface to the underlying file system, and does not actually store file information internally.

See also Model/View Programming and QAbstractItemModel.

## Member Function Documentation

### QStandardItemModel::QStandardItemModel ( QObject * parent = 0 )

Creates an empty model that contains no rows or columns with the given parent.

### QStandardItemModel::QStandardItemModel ( int rows, int columns, QObject * parent = 0 )

Creates a model with rows number of rows and columns number of columns.

### QStandardItemModel::~QStandardItemModel ()

Destroys the model.

### void QStandardItemModel::clear ()

Clears the model, removing all items.

### int QStandardItemModel::columnCount ( const QModelIndex & parent = QModelIndex() ) const `[virtual]`

Returns the number of columns in the model that contain items with the given parent.

Reimplemented from QAbstractItemModel.

### QVariant QStandardItemModel::data ( const QModelIndex & index, int role = Qt::DisplayRole ) const `[virtual]`

Returns the data for the given index and role.

Reimplemented from QAbstractItemModel.

### Qt::ItemFlags QStandardItemModel::flags ( const QModelIndex & index ) const `[virtual]`

Returns the item flags for the given index.

This model returns returns a combination of flags that enables the item (Qt::ItemIsEnabled), allows it to be selected (Qt::ItemIsSelectable) and edited (Qt::ItemIsEditable).

Reimplemented from QAbstractItemModel.

### bool QStandardItemModel::hasChildren ( const QModelIndex & parent = QModelIndex() ) const `[virtual]`

Returns true if the parent model index has child items; otherwise returns false.

Reimplemented from QAbstractItemModel.

### QModelIndex QStandardItemModel::index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const `[virtual]`

Returns a model index for the given row, column, and parent.

Reimplemented from QAbstractItemModel.

### bool QStandardItemModel::insertColumns ( int column, int count, const QModelIndex & parent = QModelIndex() ) `[virtual]`

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 column is 0, the columns are prepended to any existing columns in the parent. If column is columnCount(), the columns are appended to any existing columns in the parent. If parent has no children, a single row with count columns is inserted.

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

Reimplemented from QAbstractItemModel.

### bool QStandardItemModel::insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() ) `[virtual]`

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 row is 0, the rows are prepended to any existing rows in the parent. If row is rowCount(), the rows are appended to any existing rows in the parent. If parent has no children, a single column with count rows is inserted.

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

Reimplemented from QAbstractItemModel.

### QModelIndex QStandardItemModel::parent ( const QModelIndex & child ) const `[virtual]`

Returns a model index for the parent of the child item.

Reimplemented from QAbstractItemModel.

### bool QStandardItemModel::removeColumns ( int column, int count, const QModelIndex & parent = QModelIndex() ) `[virtual]`

Removes count columns from the model, starting with the given column. The items removed are children of the item represented by the parent model index.

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

Reimplemented from QAbstractItemModel.

### bool QStandardItemModel::removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() ) `[virtual]`

Removes count rows from the model, starting with the given row. The items removed are children of the item represented by the parent model index.

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

Reimplemented from QAbstractItemModel.

### int QStandardItemModel::rowCount ( const QModelIndex & parent = QModelIndex() ) const `[virtual]`

Returns the number of rows in the model that contain items with the given parent.

Reimplemented from QAbstractItemModel.

### bool QStandardItemModel::setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) `[virtual]`

Sets the data for the given index and role to the value specified.

Reimplemented from QAbstractItemModel.