|  | Home · Overviews · Examples |

# QStandardItem Class Reference
[com.trolltech.qt.gui module]

The `QStandardItem` class provides an item for use with the `QStandardItemModel` class. More...

## Detailed Description

The `QStandardItem` class provides an item for use with the `QStandardItemModel` class.

Items usually contain text, icons, or checkboxes.

Each item can have its own background brush which is set with the `setBackground` function. The current background brush can be found with `background`. The text label for each item can be rendered with its own font and brush. These are specified with the `setFont` and `setForeground` functions, and read with `font` and `foreground`.

By default, items are enabled, editable, selectable, checkable, and can be used both as the source of a drag and drop operation and as a drop target. Each item's flags can be changed by calling `setFlags`. Checkable items can be checked and unchecked with the `setCheckState` function. The corresponding `checkState` function indicates whether the item is currently checked.

You can store application-specific data in an item by calling `setData`.

Each item can have a two-dimensional table of child items. This makes it possible to build hierarchies of items. The typical hierarchy is the tree, in which case the child table is a table with a single column (a list).

The dimensions of the child table can be set with `setRowCount` and `setColumnCount`. Items can be positioned in the child table with `setChild`. Get a pointer to a child item with `child`. New rows and columns of children can also be inserted with `insertRow` and `insertColumn`, or appended with `appendRow` and `appendColumn`. When using the append and insert functions, the dimensions of the child table will grow as needed.

An existing row of children can be removed with `removeRow` or `takeRow`; correspondingly, a column can be removed with `removeColumn` or `takeColumn`.

An item's children can be sorted by calling `sortChildren`.

### Subclassing

When subclassing `QStandardItem` to provide custom items, it is possible to define new types for them so that they can be distinguished from the base class. The `type` function should be reimplemented to return a new type value equal to or greater than `UserType`.

Reimplement `data` and `setData` if you want to perform custom handling of data queries and/or control how an item's data is represented.

Reimplement `clone` if you want `QStandardItemModel` to be able to create instances of your custom item class on demand (see QStandardItemModel::setItemPrototype()).

Reimplement `read` and `write` if you want to control how items are represented in their serialized form.

Reimplement `operator<` if you want to control the semantics of item comparison. `operator<` determines the sorted order when sorting items with `sortChildren` or with QStandardItemModel::sort().

See also `QStandardItemModel`, Item View Convenience Classes, and Model/View Programming.