Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QStandardItem Class Reference

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

#include <qstandarditemmodel.h>

+ Inheritance diagram for QStandardItem:
+ Collaboration diagram for QStandardItem:

Public Types

enum  ItemType { Type = 0 , UserType = 1000 }
 This enum describes the types that are used to describe standard items. More...
 

Public Member Functions

 QStandardItem ()
 Constructs an item.
 
 QStandardItem (const QString &text)
 Constructs an item with the given text.
 
 QStandardItem (const QIcon &icon, const QString &text)
 Constructs an item with the given icon and text.
 
 QStandardItem (int rows, int columns=1)
 Constructs an item with rows rows and columns columns of child items.
 
virtual ~QStandardItem ()
 Destructs the item.
 
virtual QVariant data (int role=Qt::UserRole+1) const
 Returns the item's data for the given role, or an invalid QVariant if there is no data for the role.
 
virtual void multiData (QModelRoleDataSpan roleDataSpan) const
 
virtual void setData (const QVariant &value, int role=Qt::UserRole+1)
 Sets the item's data for the given role to the specified value.
 
void clearData ()
 
QString text () const
 Returns the item's text.
 
void setText (const QString &text)
 Sets the item's text to the text specified.
 
QIcon icon () const
 Returns the item's icon.
 
void setIcon (const QIcon &icon)
 Sets the item's icon to the icon specified.
 
QString toolTip () const
 Returns the item's tooltip.
 
void setToolTip (const QString &toolTip)
 Sets the item's tooltip to the string specified by toolTip.
 
QString statusTip () const
 Returns the item's status tip.
 
void setStatusTip (const QString &statusTip)
 Sets the item's status tip to the string specified by statusTip.
 
QSize sizeHint () const
 Returns the size hint set for the item, or an invalid QSize if no size hint has been set.
 
void setSizeHint (const QSize &sizeHint)
 Sets the size hint for the item to be size.
 
QFont font () const
 Returns the font used to render the item's text.
 
void setFont (const QFont &font)
 Sets the font used to display the item's text to the given font.
 
Qt::Alignment textAlignment () const
 Returns the text alignment for the item's text.
 
void setTextAlignment (Qt::Alignment textAlignment)
 Sets the text alignment for the item's text to the alignment specified.
 
QBrush background () const
 Returns the brush used to render the item's background.
 
void setBackground (const QBrush &brush)
 Sets the item's background brush to the specified brush.
 
QBrush foreground () const
 Returns the brush used to render the item's foreground (e.g.
 
void setForeground (const QBrush &brush)
 Sets the brush used to display the item's foreground (e.g.
 
Qt::CheckState checkState () const
 Returns the checked state of the item.
 
void setCheckState (Qt::CheckState checkState)
 Sets the check state of the item to be state.
 
QString accessibleText () const
 Returns the item's accessible text.
 
void setAccessibleText (const QString &accessibleText)
 Sets the item's accessible text to the string specified by accessibleText.
 
QString accessibleDescription () const
 Returns the item's accessible description.
 
void setAccessibleDescription (const QString &accessibleDescription)
 Sets the item's accessible description to the string specified by accessibleDescription.
 
Qt::ItemFlags flags () const
 Returns the item flags for the item.
 
void setFlags (Qt::ItemFlags flags)
 Sets the item flags for the item to flags.
 
bool isEnabled () const
 Returns whether the item is enabled.
 
void setEnabled (bool enabled)
 Sets whether the item is enabled.
 
bool isEditable () const
 Returns whether the item can be edited by the user.
 
void setEditable (bool editable)
 Sets whether the item is editable.
 
bool isSelectable () const
 Returns whether the item is selectable by the user.
 
void setSelectable (bool selectable)
 Sets whether the item is selectable.
 
bool isCheckable () const
 Returns whether the item is user-checkable.
 
void setCheckable (bool checkable)
 Sets whether the item is user-checkable.
 
bool isAutoTristate () const
 Returns whether the item is tristate and is controlled by QTreeWidget.
 
void setAutoTristate (bool tristate)
 Determines that the item is tristate and controlled by QTreeWidget if tristate is true.
 
bool isUserTristate () const
 
void setUserTristate (bool tristate)
 Sets whether the item is tristate and controlled by the user.
 
QStandardItemparent () const
 Returns the item's parent item, or \nullptr if the item has no parent.
 
int row () const
 Returns the row where the item is located in its parent's child table, or -1 if the item has no parent.
 
int column () const
 Returns the column where the item is located in its parent's child table, or -1 if the item has no parent.
 
QModelIndex index () const
 Returns the QModelIndex associated with this item.
 
QStandardItemModelmodel () const
 Returns the QStandardItemModel that this item belongs to.
 
int rowCount () const
 Returns the number of child item rows that the item has.
 
void setRowCount (int rows)
 Sets the number of child item rows to rows.
 
int columnCount () const
 Returns the number of child item columns that the item has.
 
void setColumnCount (int columns)
 Sets the number of child item columns to columns.
 
bool hasChildren () const
 Returns true if this item has any children; otherwise returns false.
 
QStandardItemchild (int row, int column=0) const
 Returns the child item at (row, column) if one has been set; otherwise returns \nullptr.
 
void setChild (int row, int column, QStandardItem *item)
 Sets the child item at (row, column) to item.
 
void setChild (int row, QStandardItem *item)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the child at row to item.
 
void insertRow (int row, const QList< QStandardItem * > &items)
 Inserts a row at row containing items.
 
void insertColumn (int column, const QList< QStandardItem * > &items)
 Inserts a column at column containing items.
 
void insertRows (int row, const QList< QStandardItem * > &items)
 Inserts items at row.
 
void insertRows (int row, int count)
 Inserts count rows of child items at row row.
 
void insertColumns (int column, int count)
 Inserts count columns of child items at column column.
 
void removeRow (int row)
 Removes the given row.
 
void removeColumn (int column)
 Removes the given column.
 
void removeRows (int row, int count)
 Removes count rows at row row.
 
void removeColumns (int column, int count)
 Removes count columns at column column.
 
void appendRow (const QList< QStandardItem * > &items)
 Appends a row containing items.
 
void appendRows (const QList< QStandardItem * > &items)
 Appends rows containing items.
 
void appendColumn (const QList< QStandardItem * > &items)
 Appends a column containing items.
 
void insertRow (int row, QStandardItem *item)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Inserts a row at row containing item.
 
void appendRow (QStandardItem *item)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Appends a row containing item.
 
QStandardItemtakeChild (int row, int column=0)
 Removes the child item at (row, column) without deleting it, and returns a pointer to the item.
 
QList< QStandardItem * > takeRow (int row)
 Removes row without deleting the row items, and returns a list of pointers to the removed items.
 
QList< QStandardItem * > takeColumn (int column)
 Removes column without deleting the column items, and returns a list of pointers to the removed items.
 
void sortChildren (int column, Qt::SortOrder order=Qt::AscendingOrder)
 Sorts the children of the item using the given order, by the values in the given column.
 
virtual QStandardItemclone () const
 Returns a copy of this item.
 
virtual int type () const
 Returns the type of this item.
 
virtual void read (QDataStream &in)
 Reads the item from stream in.
 
virtual void write (QDataStream &out) const
 Writes the item to stream out.
 
virtual bool operator< (const QStandardItem &other) const
 Returns true if this item is less than other; otherwise returns false.
 

Protected Member Functions

 QStandardItem (const QStandardItem &other)
 Constructs a copy of other.
 
 QStandardItem (QStandardItemPrivate &dd)
 
QStandardItemoperator= (const QStandardItem &other)
 Assigns other's data and flags to this item.
 
void emitDataChanged ()
 

Protected Attributes

QScopedPointer< QStandardItemPrivated_ptr
 

Friends

class QStandardItemModelPrivate
 
class QStandardItemModel
 

Related Symbols

(Note that these are not member symbols.)

QDataStreamoperator>> (QDataStream &in, QStandardItem &item)
 
QDataStreamoperator<< (QDataStream &out, const QStandardItem &item)
 

Detailed Description

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

Since
4.2

\inmodule QtGui

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().

Definition at line 23 of file qstandarditemmodel.h.

Member Enumeration Documentation

◆ ItemType

This enum describes the types that are used to describe standard items.

\value Type The default type for standard items. \value UserType The minimum value for custom types. Values below UserType are reserved by Qt.

You can define new user types in QStandardItem subclasses to ensure that custom items are treated specially; for example, when items are sorted.

See also
type()
Enumerator
Type 
UserType 

Definition at line 192 of file qstandarditemmodel.h.

Constructor & Destructor Documentation

◆ QStandardItem() [1/6]

QStandardItem::QStandardItem ( )

Constructs an item.

Definition at line 769 of file qstandarditemmodel.cpp.

Referenced by clone().

+ Here is the caller graph for this function:

◆ QStandardItem() [2/6]

QStandardItem::QStandardItem ( const QString & text)
explicit

Constructs an item with the given text.

Definition at line 777 of file qstandarditemmodel.cpp.

References setText(), and text().

+ Here is the call graph for this function:

◆ QStandardItem() [3/6]

QStandardItem::QStandardItem ( const QIcon & icon,
const QString & text )

Constructs an item with the given icon and text.

Definition at line 786 of file qstandarditemmodel.cpp.

References icon(), and setIcon().

+ Here is the call graph for this function:

◆ QStandardItem() [4/6]

QStandardItem::QStandardItem ( int rows,
int columns = 1 )
explicit

Constructs an item with rows rows and columns columns of child items.

Definition at line 795 of file qstandarditemmodel.cpp.

References setColumnCount(), and setRowCount().

+ Here is the call graph for this function:

◆ ~QStandardItem()

QStandardItem::~QStandardItem ( )
virtual

Destructs the item.

This causes the item's children to be destructed as well.

Definition at line 843 of file qstandarditemmodel.cpp.

References child, and d.

◆ QStandardItem() [5/6]

QStandardItem::QStandardItem ( const QStandardItem & other)
protected

Constructs a copy of other.

Note that model() is not copied.

This function is useful when reimplementing clone().

Definition at line 818 of file qstandarditemmodel.cpp.

References d, operator=(), and other().

+ Here is the call graph for this function:

◆ QStandardItem() [6/6]

QStandardItem::QStandardItem ( QStandardItemPrivate & dd)
protected

Definition at line 805 of file qstandarditemmodel.cpp.

References d.

Member Function Documentation

◆ accessibleDescription()

QString QStandardItem::accessibleDescription ( ) const
inline

Returns the item's accessible description.

The accessible description is used by assistive technologies (i.e. for users who cannot use conventional means of interaction).

See also
setAccessibleDescription(), accessibleText()

Definition at line 101 of file qstandarditemmodel.h.

References Qt::AccessibleDescriptionRole.

◆ accessibleText()

QString QStandardItem::accessibleText ( ) const
inline

Returns the item's accessible text.

The accessible text is used by assistive technologies (i.e. for users who cannot use conventional means of interaction).

See also
setAccessibleText(), accessibleDescription()

Definition at line 96 of file qstandarditemmodel.h.

References Qt::AccessibleTextRole.

◆ appendColumn()

void QStandardItem::appendColumn ( const QList< QStandardItem * > & items)
inline

Appends a column containing items.

If necessary, the row count is increased to the size of items.

See also
insertColumn()

Definition at line 267 of file qstandarditemmodel.h.

Referenced by QStandardItemModel::appendColumn().

+ Here is the caller graph for this function:

◆ appendRow() [1/2]

void QStandardItem::appendRow ( const QList< QStandardItem * > & items)
inline

Appends a row containing items.

If necessary, the column count is increased to the size of items.

See also
insertRow()

Definition at line 261 of file qstandarditemmodel.h.

References insertRow().

Referenced by QStandardItemModel::appendRow(), and src_gui_itemviews_qstandarditemmodel::wrapper1().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendRow() [2/2]

void QStandardItem::appendRow ( QStandardItem * item)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Appends a 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.

Definition at line 273 of file qstandarditemmodel.h.

References insertRow().

+ Here is the call graph for this function:

◆ appendRows()

void QStandardItem::appendRows ( const QList< QStandardItem * > & items)
inline

Appends rows containing items.

The column count will not change.

See also
insertRow()

Definition at line 264 of file qstandarditemmodel.h.

◆ background()

QBrush QStandardItem::background ( ) const
inline

Returns the brush used to render the item's background.

See also
foreground(), setBackground()

Definition at line 81 of file qstandarditemmodel.h.

References Qt::BackgroundRole.

◆ checkState()

Qt::CheckState QStandardItem::checkState ( ) const
inline

Returns the checked state of the item.

See also
setCheckState(), isCheckable()

Definition at line 91 of file qstandarditemmodel.h.

References Qt::CheckStateRole.

◆ child()

QStandardItem * QStandardItem::child ( int row,
int column = 0 ) const

Returns the child item at (row, column) if one has been set; otherwise returns \nullptr.

See also
setChild(), takeChild(), parent()

Definition at line 1849 of file qstandarditemmodel.cpp.

References d.

Referenced by QStandardItemPrivate::sortChildren().

+ Here is the caller graph for this function:

◆ clearData()

void QStandardItem::clearData ( )
Since
5.12 Removes all the data from all roles previously set.
See also
data(), setData()

Definition at line 923 of file qstandarditemmodel.cpp.

References d.

◆ clone()

QStandardItem * QStandardItem::clone ( ) const
virtual

Returns a copy of this item.

The item's children are not copied.

When subclassing QStandardItem, you can reimplement this function to provide QStandardItemModel with a factory that it can use to create new items on demand.

See also
QStandardItemModel::setItemPrototype(), operator=()

Reimplemented in CustomItem.

Definition at line 2028 of file qstandarditemmodel.cpp.

References QStandardItem().

Referenced by QStandardItemModelPrivate::createItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ column()

int QStandardItem::column ( ) const

Returns the column where the item is located in its parent's child table, or -1 if the item has no parent.

See also
row(), parent()

Definition at line 1499 of file qstandarditemmodel.cpp.

References d, and pos.

Referenced by takeRow().

+ Here is the caller graph for this function:

◆ columnCount()

int QStandardItem::columnCount ( ) const

Returns the number of child item columns that the item has.

See also
setColumnCount(), rowCount()

Definition at line 1588 of file qstandarditemmodel.cpp.

References d.

Referenced by hasChildren(), QStandardItemModel::index(), insertColumns(), insertRow(), removeColumns(), setColumnCount(), and takeColumn().

+ Here is the caller graph for this function:

◆ data()

QVariant QStandardItem::data ( int role = Qt::UserRole + 1) const
virtual

Returns the item's data for the given role, or an invalid QVariant if there is no data for the role.

If you reimplement this function, your reimplementation should call the base implementation for roles you don't handle, otherwise getting flags, e.g. by calling flags(), isCheckable(), isEditable() etc., will not work.

Note
The default implementation treats Qt::EditRole and Qt::DisplayRole as referring to the same data.

Definition at line 945 of file qstandarditemmodel.cpp.

References d, Qt::DisplayRole, and Qt::EditRole.

Referenced by QStandardItemModel::headerData().

+ Here is the caller graph for this function:

◆ emitDataChanged()

void QStandardItem::emitDataChanged ( )
protected
Since
4.4

Causes the model associated with this item to emit a \l{QAbstractItemModel::dataChanged()}{dataChanged}() signal for this item.

You normally only need to call this function if you have subclassed QStandardItem and reimplemented data() and/or setData().

See also
setData()

Definition at line 984 of file qstandarditemmodel.cpp.

References d.

◆ flags()

Qt::ItemFlags QStandardItem::flags ( ) const

Returns the item flags for the item.

The item flags determine how the user can interact with the item.

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.

See also
setFlags()

Definition at line 1014 of file qstandarditemmodel.cpp.

References Qt::ItemIsDragEnabled, Qt::ItemIsDropEnabled, Qt::ItemIsEditable, Qt::ItemIsEnabled, and Qt::ItemIsSelectable.

Referenced by read(), and write().

+ Here is the caller graph for this function:

◆ font()

QFont QStandardItem::font ( ) const
inline

Returns the font used to render the item's text.

See also
setFont()

Definition at line 71 of file qstandarditemmodel.h.

References Qt::FontRole.

◆ foreground()

QBrush QStandardItem::foreground ( ) const
inline

Returns the brush used to render the item's foreground (e.g.

text).

See also
setForeground(), background()

Definition at line 86 of file qstandarditemmodel.h.

References Qt::ForegroundRole.

◆ hasChildren()

bool QStandardItem::hasChildren ( ) const

Returns true if this item has any children; otherwise returns false.

See also
rowCount(), columnCount(), child()

Definition at line 1816 of file qstandarditemmodel.cpp.

References columnCount(), and rowCount().

+ Here is the call graph for this function:

◆ icon()

QIcon QStandardItem::icon ( ) const
inline

Returns the item's icon.

See also
setIcon(), {QAbstractItemView::iconSize}{iconSize}

Definition at line 42 of file qstandarditemmodel.h.

References Qt::DecorationRole.

Referenced by QStandardItem().

+ Here is the caller graph for this function:

◆ index()

QModelIndex QStandardItem::index ( ) const

Returns the QModelIndex associated with this item.

When you need to invoke item functionality in a QModelIndex-based API (e.g. QAbstractItemView), you can call this function to obtain an index that corresponds to the item's location in the model.

If the item is not associated with a model, an invalid QModelIndex is returned.

See also
model(), QStandardItemModel::itemFromIndex()

Definition at line 1518 of file qstandarditemmodel.cpp.

References d.

Referenced by QStandardItemModel::dropMimeData(), and sortChildren().

+ Here is the caller graph for this function:

◆ insertColumn()

void QStandardItem::insertColumn ( int column,
const QList< QStandardItem * > & items )

Inserts a column at column containing items.

If necessary, the row count is increased to the size of items.

See also
insertColumns(), insertRow()

Definition at line 1629 of file qstandarditemmodel.cpp.

References d, items, rowCount(), setRowCount(), and QList< T >::size().

Referenced by QStandardItemModel::insertColumn().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertColumns()

void QStandardItem::insertColumns ( int column,
int count )

Inserts count columns of child items at column column.

See also
insertColumn(), insertRows()

Definition at line 1659 of file qstandarditemmodel.cpp.

References columnCount(), and d.

Referenced by setColumnCount().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertRow() [1/2]

void QStandardItem::insertRow ( int row,
const QList< QStandardItem * > & items )

Inserts a row at row containing items.

If necessary, the column count is increased to the size of items.

See also
insertRows(), insertColumn()

Definition at line 1600 of file qstandarditemmodel.cpp.

References columnCount(), d, items, setColumnCount(), and QList< T >::size().

Referenced by QStandardItemModel::insertRow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertRow() [2/2]

void QStandardItem::insertRow ( int row,
QStandardItem * item )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.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 insert a single new item.

Definition at line 270 of file qstandarditemmodel.h.

References insertRow().

+ Here is the call graph for this function:

◆ insertRows() [1/2]

void QStandardItem::insertRows ( int row,
const QList< QStandardItem * > & items )

Inserts items at row.

The column count won't be changed.

See also
insertRow(), insertColumn()

Definition at line 1615 of file qstandarditemmodel.cpp.

References d, and items.

Referenced by setRowCount().

+ Here is the caller graph for this function:

◆ insertRows() [2/2]

void QStandardItem::insertRows ( int row,
int count )

Inserts count rows of child items at row row.

See also
insertRow(), insertColumns()

Definition at line 1644 of file qstandarditemmodel.cpp.

References d, and rowCount().

+ Here is the call graph for this function:

◆ isAutoTristate()

bool QStandardItem::isAutoTristate ( ) const
inline

Returns whether the item is tristate and is controlled by QTreeWidget.

The default value is false.

Since
5.6
See also
setAutoTristate(), isCheckable(), checkState()

Definition at line 129 of file qstandarditemmodel.h.

References Qt::ItemIsAutoTristate.

◆ isCheckable()

bool QStandardItem::isCheckable ( ) const
inline

Returns whether the item is user-checkable.

The default value is false.

See also
setCheckable(), checkState(), isUserTristate(), isAutoTristate()

Definition at line 124 of file qstandarditemmodel.h.

References Qt::ItemIsUserCheckable.

Referenced by setCheckable().

+ Here is the caller graph for this function:

◆ isEditable()

bool QStandardItem::isEditable ( ) const
inline

Returns whether the item can be edited by the user.

When an item is editable (and enabled), the user can edit the item by invoking one of the view's edit triggers; see QAbstractItemView::editTriggers.

The default value is true.

See also
setEditable(), flags()

Definition at line 114 of file qstandarditemmodel.h.

References Qt::ItemIsEditable.

◆ isEnabled()

bool QStandardItem::isEnabled ( ) const
inline

Returns whether the item is enabled.

When an item is enabled, the user can interact with it. The possible types of interaction are specified by the other item flags, such as isEditable() and isSelectable().

The default value is true.

See also
setEnabled(), flags()

Definition at line 109 of file qstandarditemmodel.h.

References Qt::ItemIsEnabled.

◆ isSelectable()

bool QStandardItem::isSelectable ( ) const
inline

Returns whether the item is selectable by the user.

The default value is true.

See also
setSelectable(), flags()

Definition at line 119 of file qstandarditemmodel.h.

References Qt::ItemIsSelectable.

◆ isUserTristate()

bool QStandardItem::isUserTristate ( ) const
inline
Since
5.6

Returns whether the item is tristate; that is, if it's checkable with three separate states and the user can cycle through all three states.

The default value is false.

See also
setUserTristate(), isCheckable(), checkState()

Definition at line 134 of file qstandarditemmodel.h.

References Qt::ItemIsUserTristate.

◆ model()

QStandardItemModel * QStandardItem::model ( ) const

Returns the QStandardItemModel that this item belongs to.

If the item is not a child of another item that belongs to the model, this function returns \nullptr.

See also
index()

Definition at line 1532 of file qstandarditemmodel.cpp.

References d.

Referenced by operator<(), removeColumns(), removeRows(), and QStandardItemPrivate::setModel().

+ Here is the caller graph for this function:

◆ multiData()

void QStandardItem::multiData ( QModelRoleDataSpan roleDataSpan) const
virtual
Since
6.0

Fills the roleDataSpan span with the data from this item.

The default implementation simply calls data() for each role in the span.

See also
data()

Definition at line 966 of file qstandarditemmodel.cpp.

References roleData.

◆ operator<()

bool QStandardItem::operator< ( const QStandardItem & other) const
virtual

Returns true if this item is less than other; otherwise returns false.

The default implementation uses the data for the item's sort role (see QStandardItemModel::sortRole) to perform the comparison if the item belongs to a model; otherwise, the data for the item's Qt::DisplayRole (text()) is used to perform the comparison.

sortChildren() and QStandardItemModel::sort() use this function when sorting items. If you want custom sorting, you can subclass QStandardItem and reimplement this function.

Definition at line 1987 of file qstandarditemmodel.cpp.

References Qt::DisplayRole, QAbstractItemModelPrivate::isVariantLessThan(), model(), other(), and QStandardItemModel::sortRole.

+ Here is the call graph for this function:

◆ operator=()

QStandardItem & QStandardItem::operator= ( const QStandardItem & other)
protected

Assigns other's data and flags to this item.

Note that type() and model() are not copied.

This function is useful when reimplementing clone().

Definition at line 832 of file qstandarditemmodel.cpp.

References d, and other().

Referenced by QStandardItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parent()

QStandardItem * QStandardItem::parent ( ) const

Returns the item's parent item, or \nullptr if the item has no parent.

Note
For toplevel items parent() returns \nullptr. To receive toplevel item's parent use QStandardItemModel::invisibleRootItem() instead.
See also
child(), QStandardItemModel::invisibleRootItem()

Definition at line 863 of file qstandarditemmodel.cpp.

References d.

◆ read()

void QStandardItem::read ( QDataStream & in)
virtual

Reads the item from stream in.

Only the data and flags of the item are read, not the child items.

See also
write()

Definition at line 2054 of file qstandarditemmodel.cpp.

References d, flags(), and setFlags().

+ Here is the call graph for this function:

◆ removeColumn()

void QStandardItem::removeColumn ( int column)

Removes the given column.

The items that were in the column are deleted.

See also
takeColumn(), removeColumns(), removeRow()

Definition at line 1751 of file qstandarditemmodel.cpp.

References removeColumns().

+ Here is the call graph for this function:

◆ removeColumns()

void QStandardItem::removeColumns ( int column,
int count )

Removes count columns at column column.

The items that were in those columns are deleted.

See also
removeColumn(), removeRows()

Definition at line 1789 of file qstandarditemmodel.cpp.

References columnCount(), QAbstractItemModel::columnsRemoved(), d, i, j, model(), and row().

Referenced by removeColumn(), and setColumnCount().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeRow()

void QStandardItem::removeRow ( int row)

Removes the given row.

The items that were in the row are deleted.

See also
takeRow(), removeRows(), removeColumn()

Definition at line 1740 of file qstandarditemmodel.cpp.

References removeRows().

+ Here is the call graph for this function:

◆ removeRows()

void QStandardItem::removeRows ( int row,
int count )

Removes count rows at row row.

The items that were in those rows are deleted.

See also
removeRow(), removeColumn()

Definition at line 1762 of file qstandarditemmodel.cpp.

References d, i, j, model(), qMax(), rowCount(), and QAbstractItemModel::rowsRemoved().

Referenced by removeRow(), and setRowCount().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ row()

int QStandardItem::row ( ) const

Returns the row where the item is located in its parent's child table, or -1 if the item has no parent.

See also
column(), parent()

Definition at line 1486 of file qstandarditemmodel.cpp.

References d, and pos.

Referenced by removeColumns(), and takeColumn().

+ Here is the caller graph for this function:

◆ rowCount()

int QStandardItem::rowCount ( ) const

Returns the number of child item rows that the item has.

See also
setRowCount(), columnCount()

Definition at line 1560 of file qstandarditemmodel.cpp.

References d.

Referenced by hasChildren(), QStandardItemModel::index(), insertColumn(), insertRows(), removeRows(), setRowCount(), sortChildren(), takeColumn(), and takeRow().

+ Here is the caller graph for this function:

◆ setAccessibleDescription()

void QStandardItem::setAccessibleDescription ( const QString & accessibleDescription)
inline

Sets the item's accessible description to the string specified by accessibleDescription.

The accessible description is used by assistive technologies (i.e. for users who cannot use conventional means of interaction).

See also
accessibleDescription(), setAccessibleText()

Definition at line 255 of file qstandarditemmodel.h.

References Qt::AccessibleDescriptionRole, and setData().

+ Here is the call graph for this function:

◆ setAccessibleText()

void QStandardItem::setAccessibleText ( const QString & accessibleText)
inline

Sets the item's accessible text to the string specified by accessibleText.

The accessible text is used by assistive technologies (i.e. for users who cannot use conventional means of interaction).

See also
accessibleText(), setAccessibleDescription()

Definition at line 252 of file qstandarditemmodel.h.

References Qt::AccessibleTextRole, and setData().

+ Here is the call graph for this function:

◆ setAutoTristate()

void QStandardItem::setAutoTristate ( bool tristate)

Determines that the item is tristate and controlled by QTreeWidget if tristate is true.

This enables automatic management of the state of parent items in QTreeWidget (checked if all children are checked, unchecked if all children are unchecked, or partially checked if only some children are checked).

Since
5.6
See also
isAutoTristate(), setCheckable(), setCheckState()

Definition at line 1376 of file qstandarditemmodel.cpp.

References d, and Qt::ItemIsAutoTristate.

◆ setBackground()

void QStandardItem::setBackground ( const QBrush & brush)
inline

Sets the item's background brush to the specified brush.

See also
background(), setForeground()

Definition at line 243 of file qstandarditemmodel.h.

References Qt::BackgroundRole, and setData().

+ Here is the call graph for this function:

◆ setCheckable()

void QStandardItem::setCheckable ( bool checkable)

Sets whether the item is user-checkable.

If checkable is true, the item can be checked by the user; otherwise, the user cannot check the item.

The item delegate will render a checkable item with a check box next to the item's text.

See also
isCheckable(), setCheckState(), setUserTristate(), setAutoTristate()

Definition at line 1345 of file qstandarditemmodel.cpp.

References Qt::CheckStateRole, d, isCheckable(), Qt::ItemIsUserCheckable, setData(), and Qt::Unchecked.

+ Here is the call graph for this function:

◆ setCheckState()

void QStandardItem::setCheckState ( Qt::CheckState state)
inline

Sets the check state of the item to be state.

See also
checkState(), setCheckable()

Definition at line 249 of file qstandarditemmodel.h.

References Qt::CheckStateRole, and setData().

+ Here is the call graph for this function:

◆ setChild() [1/2]

void QStandardItem::setChild ( int row,
int column,
QStandardItem * item )

Sets the child item at (row, column) to item.

This item (the parent item) takes ownership of item. If necessary, the row count and column count are increased to fit the item.

Note
Passing \nullptr as item removes the item.
See also
child()

Definition at line 1830 of file qstandarditemmodel.cpp.

References d, and item.

Referenced by QStandardItemModel::dropMimeData().

+ Here is the caller graph for this function:

◆ setChild() [2/2]

void QStandardItem::setChild ( int row,
QStandardItem * item )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the child at row to item.

Definition at line 258 of file qstandarditemmodel.h.

◆ setColumnCount()

void QStandardItem::setColumnCount ( int columns)

Sets the number of child item columns to columns.

If this is less than columnCount(), the data in the unwanted columns is discarded.

See also
columnCount(), setRowCount()

Definition at line 1572 of file qstandarditemmodel.cpp.

References columnCount(), insertColumns(), qMax(), and removeColumns().

Referenced by QStandardItem(), and insertRow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setData()

void QStandardItem::setData ( const QVariant & value,
int role = Qt::UserRole + 1 )
virtual

Sets the item's data for the given role to the specified value.

If you subclass QStandardItem and reimplement this function, your reimplementation should: \list

  • call emitDataChanged() if you do not call the base implementation of setData(). This will ensure that e.g. views using the model are notified of the changes
  • call the base implementation for roles you don't handle, otherwise setting flags, e.g. by calling setFlags(), setCheckable(), setEditable() etc., will not work. \endlist
Note
The default implementation treats Qt::EditRole and Qt::DisplayRole as referring to the same data.
See also
Qt::ItemDataRole, data(), setFlags()

Definition at line 890 of file qstandarditemmodel.cpp.

References QList< T >::begin(), d, Qt::DisplayRole, Qt::EditRole, QList< T >::end(), it, and QSet< T >::values().

Referenced by setCheckable(), setFlags(), and QStandardItemModel::setHeaderData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setEditable()

void QStandardItem::setEditable ( bool editable)

Sets whether the item is editable.

If editable is true, the item can be edited by the user; otherwise, the user cannot edit the item.

How the user can edit items in a view is determined by the view's edit triggers; see QAbstractItemView::editTriggers.

See also
isEditable(), setFlags()

Definition at line 1289 of file qstandarditemmodel.cpp.

References d, and Qt::ItemIsEditable.

◆ setEnabled()

void QStandardItem::setEnabled ( bool enabled)

Sets whether the item is enabled.

If enabled is true, the item is enabled, meaning that the user can interact with the item; if enabled is false, the user cannot interact with the item.

This flag takes precedence over the other item flags; e.g. if an item is not enabled, it cannot be selected by the user, even if the Qt::ItemIsSelectable flag has been set.

See also
isEnabled(), Qt::ItemIsEnabled, setFlags()

Definition at line 1260 of file qstandarditemmodel.cpp.

References d, and Qt::ItemIsEnabled.

◆ setFlags()

void QStandardItem::setFlags ( Qt::ItemFlags flags)

Sets the item flags for the item to flags.

The item flags determine how the user can interact with the item. This is often used to disable an item.

See also
flags(), setData()

Definition at line 999 of file qstandarditemmodel.cpp.

References setData().

Referenced by QStandardItemModelPrivate::QStandardItemModelPrivate(), and read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFont()

void QStandardItem::setFont ( const QFont & font)
inline

Sets the font used to display the item's text to the given font.

See also
font(), setText(), setForeground()

Definition at line 237 of file qstandarditemmodel.h.

References Qt::FontRole, and setData().

+ Here is the call graph for this function:

◆ setForeground()

void QStandardItem::setForeground ( const QBrush & brush)
inline

Sets the brush used to display the item's foreground (e.g.

text) to the given brush.

See also
foreground(), setBackground(), setFont()

Definition at line 246 of file qstandarditemmodel.h.

References Qt::ForegroundRole, and setData().

+ Here is the call graph for this function:

◆ setIcon()

void QStandardItem::setIcon ( const QIcon & icon)
inline

Sets the item's icon to the icon specified.

Definition at line 218 of file qstandarditemmodel.h.

References Qt::DecorationRole, and setData().

Referenced by QStandardItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRowCount()

void QStandardItem::setRowCount ( int rows)

Sets the number of child item rows to rows.

If this is less than rowCount(), the data in the unwanted rows is discarded.

See also
rowCount(), setColumnCount()

Definition at line 1544 of file qstandarditemmodel.cpp.

References insertRows(), qMax(), removeRows(), and rowCount().

Referenced by QStandardItem(), and insertColumn().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSelectable()

void QStandardItem::setSelectable ( bool selectable)

Sets whether the item is selectable.

If selectable is true, the item can be selected by the user; otherwise, the user cannot select the item.

You can control the selection behavior and mode by manipulating their view properties; see QAbstractItemView::selectionMode and QAbstractItemView::selectionBehavior.

See also
isSelectable(), setFlags()

Definition at line 1319 of file qstandarditemmodel.cpp.

References d, and Qt::ItemIsSelectable.

◆ setSizeHint()

void QStandardItem::setSizeHint ( const QSize & size)
inline

Sets the size hint for the item to be size.

If no size hint is set, the item delegate will compute the size hint based on the item data.

See also
sizeHint()

Definition at line 234 of file qstandarditemmodel.h.

References setData(), and Qt::SizeHintRole.

+ Here is the call graph for this function:

◆ setStatusTip()

void QStandardItem::setStatusTip ( const QString & statusTip)
inline

Sets the item's status tip to the string specified by statusTip.

See also
statusTip(), setToolTip(), setWhatsThis()

Definition at line 225 of file qstandarditemmodel.h.

References setData(), and Qt::StatusTipRole.

+ Here is the call graph for this function:

◆ setText()

void QStandardItem::setText ( const QString & text)
inline

Sets the item's text to the text specified.

See also
text(), setFont(), setForeground()

Definition at line 215 of file qstandarditemmodel.h.

References Qt::DisplayRole, and setData().

Referenced by QStandardItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTextAlignment()

void QStandardItem::setTextAlignment ( Qt::Alignment alignment)
inline

Sets the text alignment for the item's text to the alignment specified.

See also
textAlignment()

Definition at line 240 of file qstandarditemmodel.h.

References QVariant::fromValue(), setData(), and Qt::TextAlignmentRole.

+ Here is the call graph for this function:

◆ setToolTip()

void QStandardItem::setToolTip ( const QString & toolTip)
inline

Sets the item's tooltip to the string specified by toolTip.

See also
toolTip(), setStatusTip(), setWhatsThis()

Definition at line 221 of file qstandarditemmodel.h.

References setData(), and Qt::ToolTipRole.

+ Here is the call graph for this function:

◆ setUserTristate()

void QStandardItem::setUserTristate ( bool tristate)

Sets whether the item is tristate and controlled by the user.

If tristate is true, the user can cycle through three separate states; otherwise, the item is checkable with two states. (Note that this also requires that the item is checkable; see isCheckable().)

Since
5.6
See also
isUserTristate(), setCheckable(), setCheckState()

Definition at line 1402 of file qstandarditemmodel.cpp.

References d, and Qt::ItemIsUserTristate.

◆ sizeHint()

QSize QStandardItem::sizeHint ( ) const
inline

Returns the size hint set for the item, or an invalid QSize if no size hint has been set.

If no size hint has been set, the item delegate will compute the size hint based on the item data.

See also
setSizeHint()

Definition at line 66 of file qstandarditemmodel.h.

References Qt::SizeHintRole.

◆ sortChildren()

void QStandardItem::sortChildren ( int column,
Qt::SortOrder order = Qt::AscendingOrder )

Sorts the children of the item using the given order, by the values in the given column.

Note
This function is recursive, therefore it sorts the children of the item, its grandchildren, etc.
See also
{operator<()}

Definition at line 2003 of file qstandarditemmodel.cpp.

References d, emit, index(), rowCount(), and QAbstractItemModel::VerticalSortHint.

+ Here is the call graph for this function:

◆ statusTip()

QString QStandardItem::statusTip ( ) const
inline

Returns the item's status tip.

See also
setStatusTip(), toolTip(), whatsThis()

Definition at line 53 of file qstandarditemmodel.h.

References Qt::StatusTipRole.

◆ takeChild()

QStandardItem * QStandardItem::takeChild ( int row,
int column = 0 )

Removes the child item at (row, column) without deleting it, and returns a pointer to the item.

If there was no child at the given location, then this function returns \nullptr.

Note that this function, unlike takeRow() and takeColumn(), does not affect the dimensions of the child table.

See also
child(), takeRow(), takeColumn()

Definition at line 1868 of file qstandarditemmodel.cpp.

References QObjectData::children, d, and item.

◆ takeColumn()

QList< QStandardItem * > QStandardItem::takeColumn ( int column)

Removes column without deleting the column items, and returns a list of pointers to the removed items.

For items in the column that have not been set, the corresponding pointers in the list will be \nullptr.

See also
removeColumn(), insertColumn(), takeRow()

Definition at line 1950 of file qstandarditemmodel.cpp.

References ch, columnCount(), d, items, QList< T >::prepend(), QList< T >::reserve(), row(), and rowCount().

+ Here is the call graph for this function:

◆ takeRow()

QList< QStandardItem * > QStandardItem::takeRow ( int row)

Removes row without deleting the row items, and returns a list of pointers to the removed items.

For items in the row that have not been set, the corresponding pointers in the list will be \nullptr.

See also
removeRow(), insertRow(), takeColumn()

Definition at line 1916 of file qstandarditemmodel.cpp.

References QList< T >::append(), ch, column(), d, items, QList< T >::reserve(), and rowCount().

+ Here is the call graph for this function:

◆ text()

QString QStandardItem::text ( ) const
inline

Returns the item's text.

This is the text that's presented to the user in a view.

See also
setText()

Definition at line 37 of file qstandarditemmodel.h.

References Qt::DisplayRole.

Referenced by QStandardItem().

+ Here is the caller graph for this function:

◆ textAlignment()

int QStandardItem::textAlignment ( ) const
inline

Returns the text alignment for the item's text.

Definition at line 76 of file qstandarditemmodel.h.

References Qt::TextAlignmentRole.

◆ toolTip()

QString QStandardItem::toolTip ( ) const
inline

Returns the item's tooltip.

See also
setToolTip(), statusTip(), whatsThis()

Definition at line 47 of file qstandarditemmodel.h.

References Qt::ToolTipRole.

◆ type()

int QStandardItem::type ( ) const
virtual

Returns the type of this item.

The type is used to distinguish custom items from the base class. When subclassing QStandardItem, you should reimplement this function and return a new value greater than or equal to \l UserType.

See also
QStandardItem::Type

Reimplemented in CustomItem, and CustomItem.

Definition at line 2041 of file qstandarditemmodel.cpp.

References Type.

◆ write()

void QStandardItem::write ( QDataStream & out) const
virtual

Writes the item to stream out.

Only the data and flags of the item are written, not the child items.

See also
read()

Definition at line 2069 of file qstandarditemmodel.cpp.

References d, flags(), and out.

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ operator<<()

QDataStream & operator<< ( QDataStream & out,
const QStandardItem & item )
related
Since
4.2

Writes the QStandardItem item to stream out.

This operator uses QStandardItem::write().

See also
{Serializing Qt Data Types}

Definition at line 2102 of file qstandarditemmodel.cpp.

References item, and out.

◆ operator>>()

QDataStream & operator>> ( QDataStream & in,
QStandardItem & item )
related
Since
4.2

Reads a QStandardItem from stream in into item.

This operator uses QStandardItem::read().

See also
{Serializing Qt Data Types}

Definition at line 2086 of file qstandarditemmodel.cpp.

References item.

◆ QStandardItemModel

friend class QStandardItemModel
friend

Definition at line 212 of file qstandarditemmodel.h.

◆ QStandardItemModelPrivate

friend class QStandardItemModelPrivate
friend

Definition at line 211 of file qstandarditemmodel.h.

Member Data Documentation

◆ d_ptr

QScopedPointer<QStandardItemPrivate> QStandardItem::d_ptr
protected

Definition at line 205 of file qstandarditemmodel.h.


The documentation for this class was generated from the following files: