- class QStandardItem¶
The
QStandardItem
class provides an item for use with theQStandardItemModel
class. More…Synopsis¶
Methods¶
def
__init__()
def
accessibleText()
def
appendColumn()
def
appendRow()
def
appendRows()
def
background()
def
checkState()
def
child()
def
clearData()
def
column()
def
columnCount()
def
flags()
def
font()
def
foreground()
def
hasChildren()
def
icon()
def
index()
def
insertColumn()
def
insertColumns()
def
insertRow()
def
insertRows()
def
isAutoTristate()
def
isCheckable()
def
isDragEnabled()
def
isDropEnabled()
def
isEditable()
def
isEnabled()
def
isSelectable()
def
isUserTristate()
def
model()
def
parent()
def
removeColumn()
def
removeColumns()
def
removeRow()
def
removeRows()
def
row()
def
rowCount()
def
setBackground()
def
setCheckState()
def
setCheckable()
def
setChild()
def
setColumnCount()
def
setDragEnabled()
def
setDropEnabled()
def
setEditable()
def
setEnabled()
def
setFlags()
def
setFont()
def
setForeground()
def
setIcon()
def
setRowCount()
def
setSelectable()
def
setSizeHint()
def
setStatusTip()
def
setText()
def
setToolTip()
def
setWhatsThis()
def
sizeHint()
def
sortChildren()
def
statusTip()
def
takeChild()
def
takeColumn()
def
takeRow()
def
text()
def
textAlignment()
def
toolTip()
def
whatsThis()
Virtual methods¶
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
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 withbackground()
. The text label for each item can be rendered with its own font and brush. These are specified with thesetFont()
andsetForeground()
functions, and read withfont()
andforeground()
.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 thesetCheckState()
function. The correspondingcheckState()
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()
andsetColumnCount()
. Items can be positioned in the child table withsetChild()
. Get a pointer to a child item withchild()
. New rows and columns of children can also be inserted withinsertRow()
andinsertColumn()
, or appended withappendRow()
andappendColumn()
. 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()
ortakeRow()
; correspondingly, a column can be removed withremoveColumn()
ortakeColumn()
.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. Thetype()
function should be reimplemented to return a new type value equal to or greater thanUserType
.Reimplement
data()
andsetData()
if you want to perform custom handling of data queries and/or control how an item’s data is represented.Reimplement
clone()
if you wantQStandardItemModel
to be able to create instances of your custom item class on demand (seesetItemPrototype()
).Reimplement
read()
andwrite()
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 withsortChildren()
or withsort()
.See also
QStandardItemModel
Item View Convenience ClassesModel/View Programming
- class ItemType¶
This enum describes the types that are used to describe standard items.
Constant
Description
QStandardItem.Type
The default type for standard items.
QStandardItem.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
- __init__()¶
Constructs an item.
- __init__(other)
- Parameters:
other –
QStandardItem
Constructs a copy of
other
. Note thatmodel()
is not copied.This function is useful when reimplementing
clone()
.- __init__(text)
- Parameters:
text – str
Constructs an item with the given
text
.- __init__(icon, text)
- Parameters:
icon –
QIcon
text – str
Constructs an item with the given
icon
andtext
.- __init__(rows[, columns=1])
- Parameters:
rows – int
columns – int
Constructs an item with
rows
rows andcolumns
columns of child items.- accessibleDescription()¶
- Return type:
str
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).
- accessibleText()¶
- Return type:
str
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).
- appendColumn(items)¶
- Parameters:
items – .list of QStandardItem
Appends a column containing
items
. If necessary, the row count is increased to the size ofitems
.See also
- appendRow(item)¶
- Parameters:
item –
QStandardItem
This is an overloaded function.
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.
- appendRow(items)
- Parameters:
items – .list of QStandardItem
Appends a row containing
items
. If necessary, the column count is increased to the size ofitems
.See also
- appendRows(items)¶
- Parameters:
items – .list of QStandardItem
Appends rows containing
items
. The column count will not change.See also
Returns the brush used to render the item’s background.
See also
- checkState()¶
- Return type:
Returns the checked state of the item.
See also
- child(row[, column=0])¶
- Parameters:
row – int
column – int
- Return type:
Returns the child item at (
row
,column
) if one has been set; otherwise returnsNone
.See also
- clearData()¶
Removes all the data from all roles previously set.
- clone()¶
- Return type:
Returns a copy of this item. The item’s children are not copied.
When subclassing
QStandardItem
, you can reimplement this function to provideQStandardItemModel
with a factory that it can use to create new items on demand.See also
setItemPrototype()
operator=()
- column()¶
- Return type:
int
Returns the column where the item is located in its parent’s child table, or -1 if the item has no parent.
- columnCount()¶
- Return type:
int
Returns the number of child item columns that the item has.
See also
- data([role=Qt.UserRole + 1])¶
- Parameters:
role – int
- Return type:
object
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.
See also
- emitDataChanged()¶
Causes the model associated with this item to emit a dataChanged() signal for this item.
You normally only need to call this function if you have subclassed
QStandardItem
and reimplementeddata()
and/orsetData()
.See also
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
Returns the font used to render the item’s text.
See also
Returns the brush used to render the item’s foreground (e.g. text).
See also
- hasChildren()¶
- Return type:
bool
Returns
true
if this item has any children; otherwise returnsfalse
.See also
Returns the item’s icon.
See also
setIcon()
iconSize
- index()¶
- Return type:
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
- insertColumn(column, items)¶
- Parameters:
column – int
items – .list of QStandardItem
Inserts a column at
column
containingitems
. If necessary, the row count is increased to the size ofitems
.See also
- insertColumns(column, count)¶
- Parameters:
column – int
count – int
Inserts
count
columns of child items at columncolumn
.See also
- insertRow(row, item)¶
- Parameters:
row – int
item –
QStandardItem
This is an overloaded function.
Inserts a row at
row
containingitem
.When building a list or a tree that has only one column, this function provides a convenient way to insert a single new item.
- insertRow(row, items)
- Parameters:
row – int
items – .list of QStandardItem
Inserts a row at
row
containingitems
. If necessary, the column count is increased to the size ofitems
.See also
- insertRows(row, items)¶
- Parameters:
row – int
items – .list of QStandardItem
Inserts
items
atrow
. The column count won’t be changed.See also
- insertRows(row, count)
- Parameters:
row – int
count – int
Inserts
count
rows of child items at rowrow
.See also
- isAutoTristate()¶
- Return type:
bool
Returns whether the item is tristate and is controlled by QTreeWidget.
The default value is false.
See also
- isCheckable()¶
- Return type:
bool
Returns whether the item is user-checkable.
The default value is false.
- isDragEnabled()¶
- Return type:
bool
Returns whether the item is drag enabled. An item that is drag enabled can be dragged by the user.
The default value is true.
Note that item dragging must be enabled in the view for dragging to work; see QAbstractItemView::dragEnabled.
See also
- isDropEnabled()¶
- Return type:
bool
Returns whether the item is drop enabled. When an item is drop enabled, it can be used as a drop target.
The default value is true.
See also
- isEditable()¶
- Return type:
bool
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
- isEnabled()¶
- Return type:
bool
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()
andisSelectable()
.The default value is true.
See also
- isSelectable()¶
- Return type:
bool
Returns whether the item is selectable by the user.
The default value is true.
See also
- isUserTristate()¶
- Return type:
bool
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
- model()¶
- Return type:
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
None
.See also
- multiData(roleDataSpan)¶
- Parameters:
roleDataSpan –
QModelRoleDataSpan
Fills the
roleDataSpan
span with the data from this item.The default implementation simply calls
data()
for each role in the span.See also
- __lt__(other)¶
- Parameters:
other –
QStandardItem
- Return type:
bool
Returns
true
if this item is less thanother
; otherwise returnsfalse
.The default implementation uses the data for the item’s sort role (see
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()
andsort()
use this function when sorting items. If you want custom sorting, you can subclassQStandardItem
and reimplement this function.- parent()¶
- Return type:
Returns the item’s parent item, or
None
if the item has no parent.Note
For toplevel items parent() returns
None
. To receive toplevel item’s parent useinvisibleRootItem()
instead.See also
- read(in)¶
- Parameters:
in –
QDataStream
Reads the item from stream
in
. Only the data and flags of the item are read, not the child items.See also
- removeColumn(column)¶
- Parameters:
column – int
Removes the given
column
. The items that were in the column are deleted.See also
- removeColumns(column, count)¶
- Parameters:
column – int
count – int
Removes
count
columns at columncolumn
. The items that were in those columns are deleted.See also
- removeRow(row)¶
- Parameters:
row – int
Removes the given
row
. The items that were in the row are deleted.See also
- removeRows(row, count)¶
- Parameters:
row – int
count – int
Removes
count
rows at rowrow
. The items that were in those rows are deleted.See also
- row()¶
- Return type:
int
Returns the row where the item is located in its parent’s child table, or -1 if the item has no parent.
- rowCount()¶
- Return type:
int
Returns the number of child item rows that the item has.
See also
- setAccessibleDescription(accessibleDescription)¶
- Parameters:
accessibleDescription – str
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).
- setAccessibleText(accessibleText)¶
- Parameters:
accessibleText – str
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).
- setAutoTristate(tristate)¶
- Parameters:
tristate – bool
Determines that the item is tristate and controlled by QTreeWidget if
tristate
istrue
. 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).Sets the item’s background brush to the specified
brush
.See also
- setCheckState(checkState)¶
- Parameters:
checkState –
CheckState
Sets the check state of the item to be
state
.See also
- setCheckable(checkable)¶
- Parameters:
checkable – bool
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.
- setChild(row, item)¶
- Parameters:
row – int
item –
QStandardItem
This is an overloaded function.
Sets the child at
row
toitem
.- setChild(row, column, item)
- Parameters:
row – int
column – int
item –
QStandardItem
Sets the child item at (
row
,column
) toitem
. This item (the parent item) takes ownership ofitem
. If necessary, the row count and column count are increased to fit the item.- setColumnCount(columns)¶
- Parameters:
columns – int
Sets the number of child item columns to
columns
. If this is less thancolumnCount()
, the data in the unwanted columns is discarded.See also
- setData(value[, role=Qt.UserRole + 1])¶
- Parameters:
value – object
role – int
Sets the item’s data for the given
role
to the specifiedvalue
.If you subclass
QStandardItem
and reimplement this function, your reimplementation should: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 changescall the base implementation for roles you don’t handle, otherwise setting flags, e.g. by calling
setFlags()
,setCheckable()
,setEditable()
etc., will not work.
Note
The default implementation treats Qt::EditRole and Qt::DisplayRole as referring to the same data.
See also
- setDragEnabled(dragEnabled)¶
- Parameters:
dragEnabled – bool
Sets whether the item is drag enabled. If
dragEnabled
is true, the item can be dragged by the user; otherwise, the user cannot drag the item.Note that you also need to ensure that item dragging is enabled in the view; see QAbstractItemView::dragEnabled.
See also
- setDropEnabled(dropEnabled)¶
- Parameters:
dropEnabled – bool
Sets whether the item is drop enabled. If
dropEnabled
is true, the item can be used as a drop target; otherwise, it cannot.Note that you also need to ensure that drops are enabled in the view; see QWidget::acceptDrops(); and that the model supports the desired drop actions; see QAbstractItemModel::supportedDropActions().
See also
- setEditable(editable)¶
- Parameters:
editable – bool
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
- setEnabled(enabled)¶
- Parameters:
enabled – bool
Sets whether the item is enabled. If
enabled
is true, the item is enabled, meaning that the user can interact with the item; ifenabled
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
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.
Sets the font used to display the item’s text to the given
font
.See also
Sets the brush used to display the item’s foreground (e.g. text) to the given
brush
.See also
Sets the item’s icon to the
icon
specified.See also
- setRowCount(rows)¶
- Parameters:
rows – int
Sets the number of child item rows to
rows
. If this is less thanrowCount()
, the data in the unwanted rows is discarded.See also
- setSelectable(selectable)¶
- Parameters:
selectable – bool
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
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
- setStatusTip(statusTip)¶
- Parameters:
statusTip – str
Sets the item’s status tip to the string specified by
statusTip
.See also
- setText(text)¶
- Parameters:
text – str
Sets the item’s text to the
text
specified.See also
- setTextAlignment(textAlignment)¶
- Parameters:
textAlignment – Combination of
AlignmentFlag
Sets the text alignment for the item’s text to the
alignment
specified.See also
- setToolTip(toolTip)¶
- Parameters:
toolTip – str
Sets the item’s tooltip to the string specified by
toolTip
.See also
- setUserTristate(tristate)¶
- Parameters:
tristate – bool
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; seeisCheckable()
.)- setWhatsThis(whatsThis)¶
- Parameters:
whatsThis – str
Sets the item’s “What’s This?” help to the string specified by
whatsThis
.See also
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
Sorts the children of the item using the given
order
, by the values in the givencolumn
.Note
This function is recursive, therefore it sorts the children of the item, its grandchildren, etc.
See also
operator
- statusTip()¶
- Return type:
str
Returns the item’s status tip.
See also
- takeChild(row[, column=0])¶
- Parameters:
row – int
column – int
- Return type:
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 returnsNone
.Note that this function, unlike
takeRow()
andtakeColumn()
, does not affect the dimensions of the child table.See also
- takeColumn(column)¶
- Parameters:
column – int
- Return type:
.list of QStandardItem
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 beNone
.See also
- takeRow(row)¶
- Parameters:
row – int
- Return type:
.list of QStandardItem
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 beNone
.See also
- text()¶
- Return type:
str
Returns the item’s text. This is the text that’s presented to the user in a view.
See also
- textAlignment()¶
- Return type:
Combination of
AlignmentFlag
Returns the text alignment for the item’s text.
See also
- toolTip()¶
- Return type:
str
Returns the item’s tooltip.
See also
- type()¶
- Return type:
int
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 toUserType
.See also
- whatsThis()¶
- Return type:
str
Returns the item’s “What’s This?” help.
See also
- write(out)¶
- Parameters:
out –
QDataStream
Writes the item to stream
out
. Only the data and flags of the item are written, not the child items.See also