[][src]Struct qt_gui::QStandardItemModel

#[repr(C)]pub struct QStandardItemModel { /* fields omitted */ }

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

C++ class: QStandardItemModel.

C++ documentation:

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

QStandardItemModel can be used as a repository for standard Qt data types. It is one of the Model/View Classes and is part of Qt's model/view framework.

QStandardItemModel provides a classic item-based approach to working with the model. The items in a QStandardItemModel are provided by QStandardItem.

QStandardItemModel implements the QAbstractItemModel interface, which means that the model can be used to provide data in any view that supports that interface (such as QListView, QTableView and QTreeView, and your own custom views). For performance and flexibility, you may want to subclass QAbstractItemModel to provide support for different kinds of data repositories. For example, the QDirModel provides a model interface to the underlying file system.

When you want a list or tree, you typically create an empty QStandardItemModel and use appendRow() to add items to the model, and item() to access an item. If your model represents a table, you typically pass the dimensions of the table to the QStandardItemModel constructor and use setItem() to position items into the table. You can also use setRowCount() and setColumnCount() to alter the dimensions of the model. To insert items, use insertRow() or insertColumn(), and to remove items, use removeRow() or removeColumn().

You can set the header labels of your model with setHorizontalHeaderLabels() and setVerticalHeaderLabels().

You can search for items in the model with findItems(), and sort the model by calling sort().

Call clear() to remove all items from the model.

An example usage of QStandardItemModel to create a table:

QStandardItemModel model(4, 4); for (int row = 0; row < 4; ++row) { for (int column = 0; column < 4; ++column) { QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column)); model.setItem(row, column, item); } }

An example usage of QStandardItemModel to create a tree:

QStandardItemModel model; QStandardItem parentItem = model.invisibleRootItem(); for (int i = 0; i < 4; ++i) { QStandardItem item = new QStandardItem(QString("item %0").arg(i)); parentItem->appendRow(item); parentItem = item; }

After setting the model on a view, you typically want to react to user actions, such as an item being clicked. Since a QAbstractItemView provides QModelIndex-based signals and functions, you need a way to obtain the QStandardItem that corresponds to a given QModelIndex, and vice versa. itemFromIndex() and indexFromItem() provide this mapping. Typical usage of itemFromIndex() includes obtaining the item at the current index in a view, and obtaining the item that corresponds to an index carried by a QAbstractItemView signal, such as QAbstractItemView::clicked(). First you connect the view's signal to a slot in your class:

QTreeView *treeView = new QTreeView(this); treeView->setModel(myStandardItemModel); connect(treeView, SIGNAL(clicked(QModelIndex)), this, SLOT(clicked(QModelIndex)));

When you receive the signal, you call itemFromIndex() on the given model index to get a pointer to the item:

void MyWidget::clicked(const QModelIndex &index) { QStandardItem *item = myStandardItemModel->itemFromIndex(index); // Do stuff with the item ... }

Conversely, you must obtain the QModelIndex of an item when you want to invoke a model/view function that takes an index as argument. You can obtain the index either by using the model's indexFromItem() function, or, equivalently, by calling QStandardItem::index():

treeView->scrollTo(item->index());

You are, of course, not required to use the item-based approach; you could instead rely entirely on the QAbstractItemModel interface when working with the model, or use a combination of the two as appropriate.

Methods

impl QStandardItemModel[src]

pub fn item_changed(&self) -> Signal<(*mut QStandardItem,)>[src]

This signal is emitted whenever the data of item has changed.

Returns a built-in Qt signal QStandardItemModel::itemChanged that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal is emitted whenever the data of item has changed.

This function was introduced in Qt 4.2.

pub unsafe fn append_column(
    &self,
    items: impl CastInto<Ref<QListOfQStandardItem>>
)
[src]

Appends a column containing items. If necessary, the row count is increased to the size of items.

Calls C++ function: void QStandardItemModel::appendColumn(const QList<QStandardItem*>& items).

C++ documentation:

Appends a column containing items. If necessary, the row count is increased to the size of items.

This function was introduced in Qt 4.2.

See also insertColumn() and appendRow().

pub unsafe fn append_row_q_list_of_q_standard_item(
    &self,
    items: impl CastInto<Ref<QListOfQStandardItem>>
)
[src]

Appends a row containing items. If necessary, the column count is increased to the size of items.

Calls C++ function: void QStandardItemModel::appendRow(const QList<QStandardItem*>& items).

C++ documentation:

Appends a row containing items. If necessary, the column count is increased to the size of items.

This function was introduced in Qt 4.2.

See also insertRow() and appendColumn().

pub unsafe fn append_row_q_standard_item(
    &self,
    item: impl CastInto<Ptr<QStandardItem>>
)
[src]

This is an overloaded function.

Calls C++ function: void QStandardItemModel::appendRow(QStandardItem* item).

C++ documentation:

This is an overloaded function.

When building a list or a tree that has only one column, this function provides a convenient way to append a single new item.

This function was introduced in Qt 4.2.

pub unsafe fn clear(&self)[src]

Removes all items (including header items) from the model and sets the number of rows and columns to zero.

Calls C++ function: void QStandardItemModel::clear().

C++ documentation:

Removes all items (including header items) from the model and sets the number of rows and columns to zero.

See also removeColumns() and removeRows().

pub unsafe fn clear_item_data(
    &self,
    index: impl CastInto<Ref<QModelIndex>>
) -> bool
[src]

This is supported on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Removes the data stored in all the roles for the given index. Returns true if index is valid and data was cleared, false otherwise.

Calls C++ function: bool QStandardItemModel::clearItemData(const QModelIndex& index).

C++ documentation:

Removes the data stored in all the roles for the given index. Returns true if index is valid and data was cleared, false otherwise.

This function was introduced in Qt 5.12.

See also setData() and data().

pub unsafe fn column_count_1a(
    &self,
    parent: impl CastInto<Ref<QModelIndex>>
) -> c_int
[src]

Reimplemented from QAbstractItemModel::columnCount().

Calls C++ function: virtual int QStandardItemModel::columnCount(const QModelIndex& parent = …) const.

C++ documentation:

Reimplemented from QAbstractItemModel::columnCount().

See also setColumnCount().

pub unsafe fn column_count_0a(&self) -> c_int[src]

Reimplemented from QAbstractItemModel::columnCount().

Calls C++ function: virtual int QStandardItemModel::columnCount() const.

C++ documentation:

Reimplemented from QAbstractItemModel::columnCount().

See also setColumnCount().

pub unsafe fn data_2a(
    &self,
    index: impl CastInto<Ref<QModelIndex>>,
    role: c_int
) -> CppBox<QVariant>
[src]

Reimplemented from QAbstractItemModel::data().

Calls C++ function: virtual QVariant QStandardItemModel::data(const QModelIndex& index, int role = …) const.

C++ documentation:

Reimplemented from QAbstractItemModel::data().

See also setData().

pub unsafe fn data_1a(
    &self,
    index: impl CastInto<Ref<QModelIndex>>
) -> CppBox<QVariant>
[src]

Reimplemented from QAbstractItemModel::data().

Calls C++ function: virtual QVariant QStandardItemModel::data(const QModelIndex& index) const.

C++ documentation:

Reimplemented from QAbstractItemModel::data().

See also setData().

pub unsafe fn drop_mime_data(
    &self,
    data: impl CastInto<Ptr<QMimeData>>,
    action: DropAction,
    row: c_int,
    column: c_int,
    parent: impl CastInto<Ref<QModelIndex>>
) -> bool
[src]

Reimplemented from QAbstractItemModel::dropMimeData().

Calls C++ function: virtual bool QStandardItemModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent).

C++ documentation:

Reimplemented from QAbstractItemModel::dropMimeData().

pub unsafe fn find_items_3a(
    &self,
    text: impl CastInto<Ref<QString>>,
    flags: QFlags<MatchFlag>,
    column: c_int
) -> CppBox<QListOfQStandardItem>
[src]

Returns a list of items that match the given text, using the given flags, in the given column.

Calls C++ function: QList<QStandardItem*> QStandardItemModel::findItems(const QString& text, QFlags<Qt::MatchFlag> flags = …, int column = …) const.

C++ documentation:

Returns a list of items that match the given text, using the given flags, in the given column.

This function was introduced in Qt 4.2.

pub unsafe fn find_items_2a(
    &self,
    text: impl CastInto<Ref<QString>>,
    flags: QFlags<MatchFlag>
) -> CppBox<QListOfQStandardItem>
[src]

Returns a list of items that match the given text, using the given flags, in the given column.

Calls C++ function: QList<QStandardItem*> QStandardItemModel::findItems(const QString& text, QFlags<Qt::MatchFlag> flags = …) const.

C++ documentation:

Returns a list of items that match the given text, using the given flags, in the given column.

This function was introduced in Qt 4.2.

pub unsafe fn find_items_1a(
    &self,
    text: impl CastInto<Ref<QString>>
) -> CppBox<QListOfQStandardItem>
[src]

Returns a list of items that match the given text, using the given flags, in the given column.

Calls C++ function: QList<QStandardItem*> QStandardItemModel::findItems(const QString& text) const.

C++ documentation:

Returns a list of items that match the given text, using the given flags, in the given column.

This function was introduced in Qt 4.2.

pub unsafe fn flags(
    &self,
    index: impl CastInto<Ref<QModelIndex>>
) -> QFlags<ItemFlag>
[src]

Reimplemented from QAbstractItemModel::flags().

Calls C++ function: virtual QFlags<Qt::ItemFlag> QStandardItemModel::flags(const QModelIndex& index) const.

C++ documentation:

Reimplemented from QAbstractItemModel::flags().

pub unsafe fn has_children_1a(
    &self,
    parent: impl CastInto<Ref<QModelIndex>>
) -> bool
[src]

Reimplemented from QAbstractItemModel::hasChildren().

Calls C++ function: virtual bool QStandardItemModel::hasChildren(const QModelIndex& parent = …) const.

C++ documentation:

Reimplemented from QAbstractItemModel::hasChildren().

pub unsafe fn has_children_0a(&self) -> bool[src]

Reimplemented from QAbstractItemModel::hasChildren().

Calls C++ function: virtual bool QStandardItemModel::hasChildren() const.

C++ documentation:

Reimplemented from QAbstractItemModel::hasChildren().

pub unsafe fn header_data_3a(
    &self,
    section: c_int,
    orientation: Orientation,
    role: c_int
) -> CppBox<QVariant>
[src]

Reimplemented from QAbstractItemModel::headerData().

Calls C++ function: virtual QVariant QStandardItemModel::headerData(int section, Qt::Orientation orientation, int role = …) const.

C++ documentation:

Reimplemented from QAbstractItemModel::headerData().

See also setHeaderData().

pub unsafe fn header_data_2a(
    &self,
    section: c_int,
    orientation: Orientation
) -> CppBox<QVariant>
[src]

Reimplemented from QAbstractItemModel::headerData().

Calls C++ function: virtual QVariant QStandardItemModel::headerData(int section, Qt::Orientation orientation) const.

C++ documentation:

Reimplemented from QAbstractItemModel::headerData().

See also setHeaderData().

pub unsafe fn horizontal_header_item(&self, column: c_int) -> Ptr<QStandardItem>[src]

Returns the horizontal header item for column if one has been set; otherwise returns 0.

Calls C++ function: QStandardItem* QStandardItemModel::horizontalHeaderItem(int column) const.

C++ documentation:

Returns the horizontal header item for column if one has been set; otherwise returns 0.

This function was introduced in Qt 4.2.

See also setHorizontalHeaderItem() and verticalHeaderItem().

pub unsafe fn index_3a(
    &self,
    row: c_int,
    column: c_int,
    parent: impl CastInto<Ref<QModelIndex>>
) -> CppBox<QModelIndex>
[src]

Reimplemented from QAbstractItemModel::index().

Calls C++ function: virtual QModelIndex QStandardItemModel::index(int row, int column, const QModelIndex& parent = …) const.

C++ documentation:

Reimplemented from QAbstractItemModel::index().

pub unsafe fn index_2a(&self, row: c_int, column: c_int) -> CppBox<QModelIndex>[src]

Reimplemented from QAbstractItemModel::index().

Calls C++ function: virtual QModelIndex QStandardItemModel::index(int row, int column) const.

C++ documentation:

Reimplemented from QAbstractItemModel::index().

pub unsafe fn index_from_item(
    &self,
    item: impl CastInto<Ptr<QStandardItem>>
) -> CppBox<QModelIndex>
[src]

Returns the QModelIndex associated with the given item.

Calls C++ function: QModelIndex QStandardItemModel::indexFromItem(const QStandardItem* item) const.

C++ documentation:

Returns the QModelIndex associated with the given item.

Use this function when you want to perform an operation that requires the QModelIndex of the item, such as QAbstractItemView::scrollTo(). QStandardItem::index() is provided as convenience; it is equivalent to calling this function.

This function was introduced in Qt 4.2.

See also itemFromIndex() and QStandardItem::index().

pub unsafe fn insert_column_int_q_list_of_q_standard_item(
    &self,
    column: c_int,
    items: impl CastInto<Ref<QListOfQStandardItem>>
)
[src]

Inserts a column at column containing items. If necessary, the row count is increased to the size of items.

Calls C++ function: void QStandardItemModel::insertColumn(int column, const QList<QStandardItem*>& items).

C++ documentation:

Inserts a column at column containing items. If necessary, the row count is increased to the size of items.

This function was introduced in Qt 4.2.

See also takeColumn(), appendColumn(), and insertRow().

pub unsafe fn insert_column_int_q_model_index(
    &self,
    column: c_int,
    parent: impl CastInto<Ref<QModelIndex>>
) -> bool
[src]

Inserts a single column before the given column in the child items of the parent specified. Returns true if the column is inserted; otherwise returns false.

Calls C++ function: bool QStandardItemModel::insertColumn(int column, const QModelIndex& parent = …).

C++ documentation:

Inserts a single column before the given column in the child items of the parent specified. Returns true if the column is inserted; otherwise returns false.

See also insertColumns(), insertRow(), and removeColumn().

pub unsafe fn insert_column_int(&self, column: c_int) -> bool[src]

Inserts a single column before the given column in the child items of the parent specified. Returns true if the column is inserted; otherwise returns false.

Calls C++ function: bool QStandardItemModel::insertColumn(int column).

C++ documentation:

Inserts a single column before the given column in the child items of the parent specified. Returns true if the column is inserted; otherwise returns false.

See also insertColumns(), insertRow(), and removeColumn().

pub unsafe fn insert_columns_3a(
    &self,
    column: c_int,
    count: c_int,
    parent: impl CastInto<Ref<QModelIndex>>
) -> bool
[src]

Reimplemented from QAbstractItemModel::insertColumns().

Calls C++ function: virtual bool QStandardItemModel::insertColumns(int column, int count, const QModelIndex& parent = …).

C++ documentation:

Reimplemented from QAbstractItemModel::insertColumns().

pub unsafe fn insert_columns_2a(&self, column: c_int, count: c_int) -> bool[src]

Reimplemented from QAbstractItemModel::insertColumns().

Calls C++ function: virtual bool QStandardItemModel::insertColumns(int column, int count).

C++ documentation:

Reimplemented from QAbstractItemModel::insertColumns().

pub unsafe fn insert_row_int_q_list_of_q_standard_item(
    &self,
    row: c_int,
    items: impl CastInto<Ref<QListOfQStandardItem>>
)
[src]

Inserts a row at row containing items. If necessary, the column count is increased to the size of items.

Calls C++ function: void QStandardItemModel::insertRow(int row, const QList<QStandardItem*>& items).

C++ documentation:

Inserts a row at row containing items. If necessary, the column count is increased to the size of items.

This function was introduced in Qt 4.2.

See also takeRow(), appendRow(), and insertColumn().

pub unsafe fn insert_row_int_q_standard_item(
    &self,
    row: c_int,
    item: impl CastInto<Ptr<QStandardItem>>
)
[src]

This is an overloaded function.

Calls C++ function: void QStandardItemModel::insertRow(int row, QStandardItem* item).

C++ documentation:

This is an overloaded function.

Inserts a row at row containing item.

When building a list or a tree that has only one column, this function provides a convenient way to append a single new item.

This function was introduced in Qt 4.2.

pub unsafe fn insert_row_int_q_model_index(
    &self,
    row: c_int,
    parent: impl CastInto<Ref<QModelIndex>>
) -> bool
[src]

Inserts a single row before the given row in the child items of the parent specified. Returns true if the row is inserted; otherwise returns false.

Calls C++ function: bool QStandardItemModel::insertRow(int row, const QModelIndex& parent = …).

C++ documentation:

Inserts a single row before the given row in the child items of the parent specified. Returns true if the row is inserted; otherwise returns false.

See also insertRows(), insertColumn(), and removeRow().

pub unsafe fn insert_row_int(&self, row: c_int) -> bool[src]

Inserts a single row before the given row in the child items of the parent specified. Returns true if the row is inserted; otherwise returns false.

Calls C++ function: bool QStandardItemModel::insertRow(int row).

C++ documentation:

Inserts a single row before the given row in the child items of the parent specified. Returns true if the row is inserted; otherwise returns false.

See also insertRows(), insertColumn(), and removeRow().

pub unsafe fn insert_rows_3a(
    &self,
    row: c_int,
    count: c_int,
    parent: impl CastInto<Ref<QModelIndex>>
) -> bool
[src]

Reimplemented from QAbstractItemModel::insertRows().

Calls C++ function: virtual bool QStandardItemModel::insertRows(int row, int count, const QModelIndex& parent = …).

C++ documentation:

Reimplemented from QAbstractItemModel::insertRows().

pub unsafe fn insert_rows_2a(&self, row: c_int, count: c_int) -> bool[src]

Reimplemented from QAbstractItemModel::insertRows().

Calls C++ function: virtual bool QStandardItemModel::insertRows(int row, int count).

C++ documentation:

Reimplemented from QAbstractItemModel::insertRows().

pub unsafe fn invisible_root_item(&self) -> Ptr<QStandardItem>[src]

Returns the model's invisible root item.

Calls C++ function: QStandardItem* QStandardItemModel::invisibleRootItem() const.

C++ documentation:

Returns the model's invisible root item.

The invisible root item provides access to the model's top-level items through the QStandardItem API, making it possible to write functions that can treat top-level items and their children in a uniform way; for example, recursive functions involving a tree model.

Note: Calling index() on the QStandardItem object retrieved from this function is not valid.

This function was introduced in Qt 4.2.

pub unsafe fn item_2a(&self, row: c_int, column: c_int) -> Ptr<QStandardItem>[src]

Returns the item for the given row and column if one has been set; otherwise returns 0.

Calls C++ function: QStandardItem* QStandardItemModel::item(int row, int column = …) const.

C++ documentation:

Returns the item for the given row and column if one has been set; otherwise returns 0.

This function was introduced in Qt 4.2.

See also setItem(), takeItem(), and itemFromIndex().

pub unsafe fn item_1a(&self, row: c_int) -> Ptr<QStandardItem>[src]

Returns the item for the given row and column if one has been set; otherwise returns 0.

Calls C++ function: QStandardItem* QStandardItemModel::item(int row) const.

C++ documentation:

Returns the item for the given row and column if one has been set; otherwise returns 0.

This function was introduced in Qt 4.2.

See also setItem(), takeItem(), and itemFromIndex().

pub unsafe fn item_data(
    &self,
    index: impl CastInto<Ref<QModelIndex>>
) -> CppBox<QMapOfIntQVariant>
[src]

Reimplemented from QAbstractItemModel::itemData().

Calls C++ function: virtual QMap<int, QVariant> QStandardItemModel::itemData(const QModelIndex& index) const.

C++ documentation:

Reimplemented from QAbstractItemModel::itemData().

See also setItemData().

pub unsafe fn item_from_index(
    &self,
    index: impl CastInto<Ref<QModelIndex>>
) -> Ptr<QStandardItem>
[src]

Returns a pointer to the QStandardItem associated with the given index.

Calls C++ function: QStandardItem* QStandardItemModel::itemFromIndex(const QModelIndex& index) const.

C++ documentation:

Returns a pointer to the QStandardItem associated with the given index.

Calling this function is typically the initial step when processing QModelIndex-based signals from a view, such as QAbstractItemView::activated(). In your slot, you call itemFromIndex(), with the QModelIndex carried by the signal as argument, to obtain a pointer to the corresponding QStandardItem.

Note that this function will lazily create an item for the index (using itemPrototype()), and set it in the parent item's child table, if no item already exists at that index.

If index is an invalid index, this function returns 0.

This function was introduced in Qt 4.2.

See also indexFromItem().

pub unsafe fn item_prototype(&self) -> Ptr<QStandardItem>[src]

Returns the item prototype used by the model. The model uses the item prototype as an item factory when it needs to construct new items on demand (for instance, when a view or item delegate calls setData()).

Calls C++ function: const QStandardItem* QStandardItemModel::itemPrototype() const.

C++ documentation:

Returns the item prototype used by the model. The model uses the item prototype as an item factory when it needs to construct new items on demand (for instance, when a view or item delegate calls setData()).

This function was introduced in Qt 4.2.

See also setItemPrototype().

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QStandardItemModel::metaObject() const.

pub unsafe fn mime_data(
    &self,
    indexes: impl CastInto<Ref<QListOfQModelIndex>>
) -> QPtr<QMimeData>
[src]

Reimplemented from QAbstractItemModel::mimeData().

Calls C++ function: virtual QMimeData* QStandardItemModel::mimeData(const QList<QModelIndex>& indexes) const.

C++ documentation:

Reimplemented from QAbstractItemModel::mimeData().

pub unsafe fn mime_types(&self) -> CppBox<QStringList>[src]

Reimplemented from QAbstractItemModel::mimeTypes().

Calls C++ function: virtual QStringList QStandardItemModel::mimeTypes() const.

C++ documentation:

Reimplemented from QAbstractItemModel::mimeTypes().

pub unsafe fn new_1a(
    parent: impl CastInto<Ptr<QObject>>
) -> QBox<QStandardItemModel>
[src]

Constructs a new item model with the given parent.

Calls C++ function: [constructor] void QStandardItemModel::QStandardItemModel(QObject* parent = …).

C++ documentation:

Constructs a new item model with the given parent.

pub unsafe fn new_3a(
    rows: c_int,
    columns: c_int,
    parent: impl CastInto<Ptr<QObject>>
) -> QBox<QStandardItemModel>
[src]

Constructs a new item model that initially has rows rows and columns columns, and that has the given parent.

Calls C++ function: [constructor] void QStandardItemModel::QStandardItemModel(int rows, int columns, QObject* parent = …).

C++ documentation:

Constructs a new item model that initially has rows rows and columns columns, and that has the given parent.

pub unsafe fn new_0a() -> QBox<QStandardItemModel>[src]

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

Calls C++ function: [constructor] void QStandardItemModel::QStandardItemModel().

C++ documentation:

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

QStandardItemModel can be used as a repository for standard Qt data types. It is one of the Model/View Classes and is part of Qt's model/view framework.

QStandardItemModel provides a classic item-based approach to working with the model. The items in a QStandardItemModel are provided by QStandardItem.

QStandardItemModel implements the QAbstractItemModel interface, which means that the model can be used to provide data in any view that supports that interface (such as QListView, QTableView and QTreeView, and your own custom views). For performance and flexibility, you may want to subclass QAbstractItemModel to provide support for different kinds of data repositories. For example, the QDirModel provides a model interface to the underlying file system.

When you want a list or tree, you typically create an empty QStandardItemModel and use appendRow() to add items to the model, and item() to access an item. If your model represents a table, you typically pass the dimensions of the table to the QStandardItemModel constructor and use setItem() to position items into the table. You can also use setRowCount() and setColumnCount() to alter the dimensions of the model. To insert items, use insertRow() or insertColumn(), and to remove items, use removeRow() or removeColumn().

You can set the header labels of your model with setHorizontalHeaderLabels() and setVerticalHeaderLabels().

You can search for items in the model with findItems(), and sort the model by calling sort().

Call clear() to remove all items from the model.

An example usage of QStandardItemModel to create a table:

QStandardItemModel model(4, 4); for (int row = 0; row < 4; ++row) { for (int column = 0; column < 4; ++column) { QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column)); model.setItem(row, column, item); } }

An example usage of QStandardItemModel to create a tree:

QStandardItemModel model; QStandardItem parentItem = model.invisibleRootItem(); for (int i = 0; i < 4; ++i) { QStandardItem item = new QStandardItem(QString("item %0").arg(i)); parentItem->appendRow(item); parentItem = item; }

After setting the model on a view, you typically want to react to user actions, such as an item being clicked. Since a QAbstractItemView provides QModelIndex-based signals and functions, you need a way to obtain the QStandardItem that corresponds to a given QModelIndex, and vice versa. itemFromIndex() and indexFromItem() provide this mapping. Typical usage of itemFromIndex() includes obtaining the item at the current index in a view, and obtaining the item that corresponds to an index carried by a QAbstractItemView signal, such as QAbstractItemView::clicked(). First you connect the view's signal to a slot in your class:

QTreeView *treeView = new QTreeView(this); treeView->setModel(myStandardItemModel); connect(treeView, SIGNAL(clicked(QModelIndex)), this, SLOT(clicked(QModelIndex)));

When you receive the signal, you call itemFromIndex() on the given model index to get a pointer to the item:

void MyWidget::clicked(const QModelIndex &index) { QStandardItem *item = myStandardItemModel->itemFromIndex(index); // Do stuff with the item ... }

Conversely, you must obtain the QModelIndex of an item when you want to invoke a model/view function that takes an index as argument. You can obtain the index either by using the model's indexFromItem() function, or, equivalently, by calling QStandardItem::index():

treeView->scrollTo(item->index());

You are, of course, not required to use the item-based approach; you could instead rely entirely on the QAbstractItemModel interface when working with the model, or use a combination of the two as appropriate.

pub unsafe fn new_2a(rows: c_int, columns: c_int) -> QBox<QStandardItemModel>[src]

Constructs a new item model that initially has rows rows and columns columns, and that has the given parent.

Calls C++ function: [constructor] void QStandardItemModel::QStandardItemModel(int rows, int columns).

C++ documentation:

Constructs a new item model that initially has rows rows and columns columns, and that has the given parent.

pub unsafe fn parent(
    &self,
    child: impl CastInto<Ref<QModelIndex>>
) -> CppBox<QModelIndex>
[src]

Reimplemented from QAbstractItemModel::parent().

Calls C++ function: virtual QModelIndex QStandardItemModel::parent(const QModelIndex& child) const.

C++ documentation:

Reimplemented from QAbstractItemModel::parent().

pub unsafe fn qt_metacall(
    &self,
    arg1: Call,
    arg2: c_int,
    arg3: *mut *mut c_void
) -> c_int
[src]

Calls C++ function: virtual int QStandardItemModel::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(&self, arg1: *const c_char) -> *mut c_void[src]

Calls C++ function: virtual void* QStandardItemModel::qt_metacast(const char* arg1).

pub unsafe fn remove_columns_3a(
    &self,
    column: c_int,
    count: c_int,
    parent: impl CastInto<Ref<QModelIndex>>
) -> bool
[src]

Reimplemented from QAbstractItemModel::removeColumns().

Calls C++ function: virtual bool QStandardItemModel::removeColumns(int column, int count, const QModelIndex& parent = …).

C++ documentation:

Reimplemented from QAbstractItemModel::removeColumns().

pub unsafe fn remove_columns_2a(&self, column: c_int, count: c_int) -> bool[src]

Reimplemented from QAbstractItemModel::removeColumns().

Calls C++ function: virtual bool QStandardItemModel::removeColumns(int column, int count).

C++ documentation:

Reimplemented from QAbstractItemModel::removeColumns().

pub unsafe fn remove_rows_3a(
    &self,
    row: c_int,
    count: c_int,
    parent: impl CastInto<Ref<QModelIndex>>
) -> bool
[src]

Reimplemented from QAbstractItemModel::removeRows().

Calls C++ function: virtual bool QStandardItemModel::removeRows(int row, int count, const QModelIndex& parent = …).

C++ documentation:

Reimplemented from QAbstractItemModel::removeRows().

pub unsafe fn remove_rows_2a(&self, row: c_int, count: c_int) -> bool[src]

Reimplemented from QAbstractItemModel::removeRows().

Calls C++ function: virtual bool QStandardItemModel::removeRows(int row, int count).

C++ documentation:

Reimplemented from QAbstractItemModel::removeRows().

pub unsafe fn row_count_1a(
    &self,
    parent: impl CastInto<Ref<QModelIndex>>
) -> c_int
[src]

Reimplemented from QAbstractItemModel::rowCount().

Calls C++ function: virtual int QStandardItemModel::rowCount(const QModelIndex& parent = …) const.

C++ documentation:

Reimplemented from QAbstractItemModel::rowCount().

See also setRowCount().

pub unsafe fn row_count_0a(&self) -> c_int[src]

Reimplemented from QAbstractItemModel::rowCount().

Calls C++ function: virtual int QStandardItemModel::rowCount() const.

C++ documentation:

Reimplemented from QAbstractItemModel::rowCount().

See also setRowCount().

pub unsafe fn set_column_count(&self, columns: c_int)[src]

Sets the number of columns in this model to columns. If this is less than columnCount(), the data in the unwanted columns is discarded.

Calls C++ function: void QStandardItemModel::setColumnCount(int columns).

C++ documentation:

Sets the number of columns in this model to columns. If this is less than columnCount(), the data in the unwanted columns is discarded.

This function was introduced in Qt 4.2.

See also columnCount() and setRowCount().

pub unsafe fn set_data_3a(
    &self,
    index: impl CastInto<Ref<QModelIndex>>,
    value: impl CastInto<Ref<QVariant>>,
    role: c_int
) -> bool
[src]

Reimplemented from QAbstractItemModel::setData().

Calls C++ function: virtual bool QStandardItemModel::setData(const QModelIndex& index, const QVariant& value, int role = …).

C++ documentation:

Reimplemented from QAbstractItemModel::setData().

See also data().

pub unsafe fn set_data_2a(
    &self,
    index: impl CastInto<Ref<QModelIndex>>,
    value: impl CastInto<Ref<QVariant>>
) -> bool
[src]

Reimplemented from QAbstractItemModel::setData().

Calls C++ function: virtual bool QStandardItemModel::setData(const QModelIndex& index, const QVariant& value).

C++ documentation:

Reimplemented from QAbstractItemModel::setData().

See also data().

pub unsafe fn set_header_data_4a(
    &self,
    section: c_int,
    orientation: Orientation,
    value: impl CastInto<Ref<QVariant>>,
    role: c_int
) -> bool
[src]

Reimplemented from QAbstractItemModel::setHeaderData().

Calls C++ function: virtual bool QStandardItemModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role = …).

C++ documentation:

Reimplemented from QAbstractItemModel::setHeaderData().

See also headerData().

pub unsafe fn set_header_data_3a(
    &self,
    section: c_int,
    orientation: Orientation,
    value: impl CastInto<Ref<QVariant>>
) -> bool
[src]

Reimplemented from QAbstractItemModel::setHeaderData().

Calls C++ function: virtual bool QStandardItemModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant& value).

C++ documentation:

Reimplemented from QAbstractItemModel::setHeaderData().

See also headerData().

pub unsafe fn set_horizontal_header_item(
    &self,
    column: c_int,
    item: impl CastInto<Ptr<QStandardItem>>
)
[src]

Sets the horizontal header item for column to item. The model takes ownership of the item. If necessary, the column count is increased to fit the item. The previous header item (if there was one) is deleted.

Calls C++ function: void QStandardItemModel::setHorizontalHeaderItem(int column, QStandardItem* item).

C++ documentation:

Sets the horizontal header item for column to item. The model takes ownership of the item. If necessary, the column count is increased to fit the item. The previous header item (if there was one) is deleted.

This function was introduced in Qt 4.2.

See also horizontalHeaderItem(), setHorizontalHeaderLabels(), and setVerticalHeaderItem().

pub unsafe fn set_horizontal_header_labels(
    &self,
    labels: impl CastInto<Ref<QStringList>>
)
[src]

Sets the horizontal header labels using labels. If necessary, the column count is increased to the size of labels.

Calls C++ function: void QStandardItemModel::setHorizontalHeaderLabels(const QStringList& labels).

C++ documentation:

Sets the horizontal header labels using labels. If necessary, the column count is increased to the size of labels.

This function was introduced in Qt 4.2.

See also setHorizontalHeaderItem().

pub unsafe fn set_item_3a(
    &self,
    row: c_int,
    column: c_int,
    item: impl CastInto<Ptr<QStandardItem>>
)
[src]

Sets the item for the given row and column to item. The model takes ownership of the item. If necessary, the row count and column count are increased to fit the item. The previous item at the given location (if there was one) is deleted.

Calls C++ function: void QStandardItemModel::setItem(int row, int column, QStandardItem* item).

C++ documentation:

Sets the item for the given row and column to item. The model takes ownership of the item. If necessary, the row count and column count are increased to fit the item. The previous item at the given location (if there was one) is deleted.

This function was introduced in Qt 4.2.

See also item().

pub unsafe fn set_item_2a(
    &self,
    row: c_int,
    item: impl CastInto<Ptr<QStandardItem>>
)
[src]

This is an overloaded function.

Calls C++ function: void QStandardItemModel::setItem(int row, QStandardItem* item).

C++ documentation:

This is an overloaded function.

pub unsafe fn set_item_data(
    &self,
    index: impl CastInto<Ref<QModelIndex>>,
    roles: impl CastInto<Ref<QMapOfIntQVariant>>
) -> bool
[src]

Reimplemented from QAbstractItemModel::setItemData().

Calls C++ function: virtual bool QStandardItemModel::setItemData(const QModelIndex& index, const QMap<int, QVariant>& roles).

C++ documentation:

Reimplemented from QAbstractItemModel::setItemData().

See also itemData().

pub unsafe fn set_item_prototype(&self, item: impl CastInto<Ptr<QStandardItem>>)[src]

Sets the item prototype for the model to the specified item. The model takes ownership of the prototype.

Calls C++ function: void QStandardItemModel::setItemPrototype(const QStandardItem* item).

C++ documentation:

Sets the item prototype for the model to the specified item. The model takes ownership of the prototype.

The item prototype acts as a QStandardItem factory, by relying on the QStandardItem::clone() function. To provide your own prototype, subclass QStandardItem, reimplement QStandardItem::clone() and set the prototype to be an instance of your custom class. Whenever QStandardItemModel needs to create an item on demand (for instance, when a view or item delegate calls setData())), the new items will be instances of your custom class.

This function was introduced in Qt 4.2.

See also itemPrototype() and QStandardItem::clone().

pub unsafe fn set_item_role_names(
    &self,
    role_names: impl CastInto<Ref<QHashOfIntQByteArray>>
)
[src]

Sets the item role names to roleNames.

Calls C++ function: void QStandardItemModel::setItemRoleNames(const QHash<int, QByteArray>& roleNames).

C++ documentation:

Sets the item role names to roleNames.

pub unsafe fn set_row_count(&self, rows: c_int)[src]

Sets the number of rows in this model to rows. If this is less than rowCount(), the data in the unwanted rows is discarded.

Calls C++ function: void QStandardItemModel::setRowCount(int rows).

C++ documentation:

Sets the number of rows in this model to rows. If this is less than rowCount(), the data in the unwanted rows is discarded.

This function was introduced in Qt 4.2.

See also rowCount() and setColumnCount().

pub unsafe fn set_sort_role(&self, role: c_int)[src]

This property holds the item role that is used to query the model's data when sorting items

Calls C++ function: void QStandardItemModel::setSortRole(int role).

C++ documentation:

This property holds the item role that is used to query the model's data when sorting items

The default value is Qt::DisplayRole.

This property was introduced in Qt 4.2.

Access functions:

int sortRole() const
void setSortRole(int role)

See also sort() and QStandardItem::sortChildren().

pub unsafe fn set_vertical_header_item(
    &self,
    row: c_int,
    item: impl CastInto<Ptr<QStandardItem>>
)
[src]

Sets the vertical header item for row to item. The model takes ownership of the item. If necessary, the row count is increased to fit the item. The previous header item (if there was one) is deleted.

Calls C++ function: void QStandardItemModel::setVerticalHeaderItem(int row, QStandardItem* item).

C++ documentation:

Sets the vertical header item for row to item. The model takes ownership of the item. If necessary, the row count is increased to fit the item. The previous header item (if there was one) is deleted.

This function was introduced in Qt 4.2.

See also verticalHeaderItem(), setVerticalHeaderLabels(), and setHorizontalHeaderItem().

pub unsafe fn set_vertical_header_labels(
    &self,
    labels: impl CastInto<Ref<QStringList>>
)
[src]

Sets the vertical header labels using labels. If necessary, the row count is increased to the size of labels.

Calls C++ function: void QStandardItemModel::setVerticalHeaderLabels(const QStringList& labels).

C++ documentation:

Sets the vertical header labels using labels. If necessary, the row count is increased to the size of labels.

This function was introduced in Qt 4.2.

See also setVerticalHeaderItem().

pub unsafe fn sibling(
    &self,
    row: c_int,
    column: c_int,
    idx: impl CastInto<Ref<QModelIndex>>
) -> CppBox<QModelIndex>
[src]

Reimplemented from QAbstractItemModel::sibling().

Calls C++ function: virtual QModelIndex QStandardItemModel::sibling(int row, int column, const QModelIndex& idx) const.

C++ documentation:

Reimplemented from QAbstractItemModel::sibling().

pub unsafe fn sort_2a(&self, column: c_int, order: SortOrder)[src]

Reimplemented from QAbstractItemModel::sort().

Calls C++ function: virtual void QStandardItemModel::sort(int column, Qt::SortOrder order = …).

C++ documentation:

Reimplemented from QAbstractItemModel::sort().

pub unsafe fn sort_1a(&self, column: c_int)[src]

Reimplemented from QAbstractItemModel::sort().

Calls C++ function: virtual void QStandardItemModel::sort(int column).

C++ documentation:

Reimplemented from QAbstractItemModel::sort().

pub unsafe fn sort_role(&self) -> c_int[src]

This property holds the item role that is used to query the model's data when sorting items

Calls C++ function: int QStandardItemModel::sortRole() const.

C++ documentation:

This property holds the item role that is used to query the model's data when sorting items

The default value is Qt::DisplayRole.

This property was introduced in Qt 4.2.

Access functions:

int sortRole() const
void setSortRole(int role)

See also sort() and QStandardItem::sortChildren().

pub unsafe fn static_meta_object() -> Ref<QMetaObject>[src]

Returns a reference to the staticMetaObject field.

pub unsafe fn supported_drop_actions(&self) -> QFlags<DropAction>[src]

Reimplemented from QAbstractItemModel::supportedDropActions().

Calls C++ function: virtual QFlags<Qt::DropAction> QStandardItemModel::supportedDropActions() const.

C++ documentation:

Reimplemented from QAbstractItemModel::supportedDropActions().

QStandardItemModel supports both copy and move.

pub unsafe fn take_column(&self, column: c_int) -> CppBox<QListOfQStandardItem>[src]

Removes the given column without deleting the column items, and returns a list of pointers to the removed items. The model releases ownership of the items. For items in the column that have not been set, the corresponding pointers in the list will be 0.

Calls C++ function: QList<QStandardItem*> QStandardItemModel::takeColumn(int column).

C++ documentation:

Removes the given column without deleting the column items, and returns a list of pointers to the removed items. The model releases ownership of the items. For items in the column that have not been set, the corresponding pointers in the list will be 0.

This function was introduced in Qt 4.2.

See also takeRow().

pub unsafe fn take_horizontal_header_item(
    &self,
    column: c_int
) -> Ptr<QStandardItem>
[src]

Removes the horizontal header item at column from the header without deleting it, and returns a pointer to the item. The model releases ownership of the item.

Calls C++ function: QStandardItem* QStandardItemModel::takeHorizontalHeaderItem(int column).

C++ documentation:

Removes the horizontal header item at column from the header without deleting it, and returns a pointer to the item. The model releases ownership of the item.

This function was introduced in Qt 4.2.

See also horizontalHeaderItem() and takeVerticalHeaderItem().

pub unsafe fn take_item_2a(
    &self,
    row: c_int,
    column: c_int
) -> Ptr<QStandardItem>
[src]

Removes the item at (row, column) without deleting it. The model releases ownership of the item.

Calls C++ function: QStandardItem* QStandardItemModel::takeItem(int row, int column = …).

C++ documentation:

Removes the item at (row, column) without deleting it. The model releases ownership of the item.

This function was introduced in Qt 4.2.

See also item(), takeRow(), and takeColumn().

pub unsafe fn take_item_1a(&self, row: c_int) -> Ptr<QStandardItem>[src]

Removes the item at (row, column) without deleting it. The model releases ownership of the item.

Calls C++ function: QStandardItem* QStandardItemModel::takeItem(int row).

C++ documentation:

Removes the item at (row, column) without deleting it. The model releases ownership of the item.

This function was introduced in Qt 4.2.

See also item(), takeRow(), and takeColumn().

pub unsafe fn take_row(&self, row: c_int) -> CppBox<QListOfQStandardItem>[src]

Removes the given row without deleting the row items, and returns a list of pointers to the removed items. The model releases ownership of the items. For items in the row that have not been set, the corresponding pointers in the list will be 0.

Calls C++ function: QList<QStandardItem*> QStandardItemModel::takeRow(int row).

C++ documentation:

Removes the given row without deleting the row items, and returns a list of pointers to the removed items. The model releases ownership of the items. For items in the row that have not been set, the corresponding pointers in the list will be 0.

This function was introduced in Qt 4.2.

See also takeColumn().

pub unsafe fn take_vertical_header_item(&self, row: c_int) -> Ptr<QStandardItem>[src]

Removes the vertical header item at row from the header without deleting it, and returns a pointer to the item. The model releases ownership of the item.

Calls C++ function: QStandardItem* QStandardItemModel::takeVerticalHeaderItem(int row).

C++ documentation:

Removes the vertical header item at row from the header without deleting it, and returns a pointer to the item. The model releases ownership of the item.

This function was introduced in Qt 4.2.

See also verticalHeaderItem() and takeHorizontalHeaderItem().

pub unsafe fn tr(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QStandardItemModel::tr(const char* s, const char* c, int n).

pub unsafe fn tr_utf8(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QStandardItemModel::trUtf8(const char* s, const char* c, int n).

pub unsafe fn vertical_header_item(&self, row: c_int) -> Ptr<QStandardItem>[src]

Returns the vertical header item for row row if one has been set; otherwise returns 0.

Calls C++ function: QStandardItem* QStandardItemModel::verticalHeaderItem(int row) const.

C++ documentation:

Returns the vertical header item for row row if one has been set; otherwise returns 0.

This function was introduced in Qt 4.2.

See also setVerticalHeaderItem() and horizontalHeaderItem().

Trait Implementations

impl CppDeletable for QStandardItemModel[src]

unsafe fn delete(&self)[src]

Destructs the model. The model destroys all its items.

Calls C++ function: virtual [destructor] void QStandardItemModel::~QStandardItemModel().

C++ documentation:

Destructs the model. The model destroys all its items.

impl Deref for QStandardItemModel[src]

type Target = QAbstractItemModel

The resulting type after dereferencing.

fn deref(&self) -> &QAbstractItemModel[src]

Calls C++ function: QAbstractItemModel* static_cast<QAbstractItemModel*>(QStandardItemModel* ptr).

impl DynamicCast<QStandardItemModel> for QAbstractItemModel[src]

unsafe fn dynamic_cast(ptr: Ptr<QAbstractItemModel>) -> Ptr<QStandardItemModel>[src]

Calls C++ function: QStandardItemModel* dynamic_cast<QStandardItemModel*>(QAbstractItemModel* ptr).

impl DynamicCast<QStandardItemModel> for QObject[src]

unsafe fn dynamic_cast(ptr: Ptr<QObject>) -> Ptr<QStandardItemModel>[src]

Calls C++ function: QStandardItemModel* dynamic_cast<QStandardItemModel*>(QObject* ptr).

impl StaticDowncast<QStandardItemModel> for QAbstractItemModel[src]

unsafe fn static_downcast(
    ptr: Ptr<QAbstractItemModel>
) -> Ptr<QStandardItemModel>
[src]

Calls C++ function: QStandardItemModel* static_cast<QStandardItemModel*>(QAbstractItemModel* ptr).

impl StaticDowncast<QStandardItemModel> for QObject[src]

unsafe fn static_downcast(ptr: Ptr<QObject>) -> Ptr<QStandardItemModel>[src]

Calls C++ function: QStandardItemModel* static_cast<QStandardItemModel*>(QObject* ptr).

impl StaticUpcast<QAbstractItemModel> for QStandardItemModel[src]

unsafe fn static_upcast(ptr: Ptr<QStandardItemModel>) -> Ptr<QAbstractItemModel>[src]

Calls C++ function: QAbstractItemModel* static_cast<QAbstractItemModel*>(QStandardItemModel* ptr).

impl StaticUpcast<QObject> for QStandardItemModel[src]

unsafe fn static_upcast(ptr: Ptr<QStandardItemModel>) -> Ptr<QObject>[src]

Calls C++ function: QObject* static_cast<QObject*>(QStandardItemModel* ptr).

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.