QTreeWidgetItem

The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class. More

Inheritance diagram of PySide2.QtWidgets.QTreeWidgetItem

Synopsis

Functions

Virtual functions

Detailed Description

Tree widget items are used to hold rows of information for tree widgets. Rows usually contain several columns of data, each of which can contain a text label and an icon.

The QTreeWidgetItem class is a convenience class that replaces the QListViewItem class in Qt 3. It provides an item for use with the QTreeWidget class.

Items are usually constructed with a parent that is either a QTreeWidget (for top-level items) or a QTreeWidgetItem (for items on lower levels of the tree). For example, the following code constructs a top-level item to represent cities of the world, and adds a entry for Oslo as a child item:

cities =  QTreeWidgetItem(treeWidget)
cities.setText(0, tr("Cities"))
osloItem =  QTreeWidgetItem(cities)
osloItem.setText(0, tr("Oslo"))
osloItem.setText(1, tr("Yes"))

Items can be added in a particular order by specifying the item they follow when they are constructed:

planets =  QTreeWidgetItem(treeWidget, cities)

planets.setText(0, tr("Planets"))

Each column in an 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 column can be rendered with its own font and brush. These are specified with the setFont() and setForeground() functions, and read with font() and foreground() .

The main difference between top-level items and those in lower levels of the tree is that a top-level item has no parent() . This information can be used to tell the difference between items, and is useful to know when inserting and removing items from the tree. Children of an item can be removed with takeChild() and inserted at a given index in the list of children with the insertChild() function.

By default, items are enabled, selectable, checkable, and can be the source of a drag and drop operation. Each item’s flags can be changed by calling setFlags() with the appropriate value (see ItemFlags ). Checkable items can be checked and unchecked with the setCheckState() function. The corresponding checkState() function indicates whether the item is currently checked.

Subclassing

When subclassing QTreeWidgetItem to provide custom items, it is possible to define new types for them so that they can be distinguished from standard items. The constructors for subclasses that require this feature need to call the base class constructor with a new type value equal to or greater than UserType .

class QTreeWidgetItem(treeview, after[, type=Type])

QTreeWidgetItem(treeview, strings[, type=Type])

QTreeWidgetItem(treeview[, type=Type])

QTreeWidgetItem(parent, after[, type=Type])

QTreeWidgetItem(parent, strings[, type=Type])

QTreeWidgetItem(parent[, type=Type])

QTreeWidgetItem(strings[, type=Type])

QTreeWidgetItem(other)

QTreeWidgetItem([type=Type])

param type

int

param parent

QTreeWidgetItem

param strings

list of strings

param treeview

QTreeWidget

param after

QTreeWidgetItem

param other

QTreeWidgetItem

Constructs a tree widget item of the specified type and inserts it into the given parent after the preceding item.

See also

type()

Constructs a tree widget item of the specified type and appends it to the items in the given parent .

See also

type()

Constructs a tree widget item of the specified type that is inserted into the parent after the preceding child item.

See also

type()

Constructs a tree widget item and append it to the given parent .

See also

type()

Constructs a tree widget item of the specified type . The item must be inserted into a tree widget.

See also

type()

PySide2.QtWidgets.QTreeWidgetItem.ItemType

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

Constant

Description

QTreeWidgetItem.Type

The default type for tree widget items.

QTreeWidgetItem.UserType

The minimum value for custom types. Values below are reserved by Qt.

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

See also

type()

PySide2.QtWidgets.QTreeWidgetItem.ChildIndicatorPolicy

Constant

Description

QTreeWidgetItem.ShowIndicator

The controls for expanding and collapsing will be shown for this item even if there are no children.

QTreeWidgetItem.DontShowIndicator

The controls for expanding and collapsing will never be shown even if there are children. If the node is forced open the user will not be able to expand or collapse the item.

QTreeWidgetItem.DontShowIndicatorWhenChildless

The controls for expanding and collapsing will be shown if the item contains children.

PySide2.QtWidgets.QTreeWidgetItem.addChild(child)
Parameters

childQTreeWidgetItem

Appends the child item to the list of children.

PySide2.QtWidgets.QTreeWidgetItem.addChildren(children)
Parameters

children

Appends the given list of children to the item.

PySide2.QtWidgets.QTreeWidgetItem.background(column)
Parameters

columnint

Return type

QBrush

Returns the brush used to render the background of the specified column .

PySide2.QtWidgets.QTreeWidgetItem.backgroundColor(column)
Parameters

columnint

Return type

QColor

Note

This function is deprecated.

This function is deprecated. Use background() instead.

PySide2.QtWidgets.QTreeWidgetItem.checkState(column)
Parameters

columnint

Return type

CheckState

Returns the check state of the label in the given column .

See also

setCheckState() CheckState

PySide2.QtWidgets.QTreeWidgetItem.child(index)
Parameters

indexint

Return type

QTreeWidgetItem

Returns the item at the given index in the list of the item’s children.

See also

parent()

PySide2.QtWidgets.QTreeWidgetItem.childCount()
Return type

int

Returns the number of child items.

PySide2.QtWidgets.QTreeWidgetItem.childIndicatorPolicy()
Return type

ChildIndicatorPolicy

Returns the item indicator policy. This policy decides when the tree branch expand/collapse indicator is shown.

PySide2.QtWidgets.QTreeWidgetItem.clone()
Return type

QTreeWidgetItem

Creates a deep copy of the item and of its children.

PySide2.QtWidgets.QTreeWidgetItem.columnCount()
Return type

int

Returns the number of columns in the item.

PySide2.QtWidgets.QTreeWidgetItem.data(column, role)
Parameters
  • columnint

  • roleint

Return type

object

Returns the value for the item’s column and role .

See also

setData()

PySide2.QtWidgets.QTreeWidgetItem.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 QTreeWidgetItem and reimplemented data() and/or setData() .

See also

setData()

PySide2.QtWidgets.QTreeWidgetItem.flags()
Return type

ItemFlags

Returns the flags used to describe the item. These determine whether the item can be checked, edited, and selected.

The default value for flags is ItemIsSelectable | ItemIsUserCheckable | ItemIsEnabled | ItemIsDragEnabled | ItemIsDropEnabled .

See also

setFlags()

PySide2.QtWidgets.QTreeWidgetItem.font(column)
Parameters

columnint

Return type

QFont

Returns the font used to render the text in the specified column .

See also

setFont()

PySide2.QtWidgets.QTreeWidgetItem.foreground(column)
Parameters

columnint

Return type

QBrush

Returns the brush used to render the foreground (e.g. text) of the specified column .

PySide2.QtWidgets.QTreeWidgetItem.icon(column)
Parameters

columnint

Return type

QIcon

Returns the icon that is displayed in the specified column .

See also

setIcon() iconSize

PySide2.QtWidgets.QTreeWidgetItem.indexOfChild(child)
Parameters

childQTreeWidgetItem

Return type

int

Returns the index of the given child in the item’s list of children.

PySide2.QtWidgets.QTreeWidgetItem.insertChild(index, child)
Parameters

Inserts the child item at index in the list of children.

If the child has already been inserted somewhere else it won’t be inserted again.

PySide2.QtWidgets.QTreeWidgetItem.insertChildren(index, children)
Parameters
  • indexint

  • children

Inserts the given list of children into the list of the item children at index .

Children that have already been inserted somewhere else won’t be inserted.

PySide2.QtWidgets.QTreeWidgetItem.isDisabled()
Return type

bool

Returns true if the item is disabled; otherwise returns false .

See also

setFlags()

PySide2.QtWidgets.QTreeWidgetItem.isExpanded()
Return type

bool

Returns true if the item is expanded, otherwise returns false .

See also

setExpanded()

PySide2.QtWidgets.QTreeWidgetItem.isFirstColumnSpanned()
Return type

bool

Returns true if the item is spanning all the columns in a row; otherwise returns false .

PySide2.QtWidgets.QTreeWidgetItem.isHidden()
Return type

bool

Returns true if the item is hidden, otherwise returns false .

See also

setHidden()

PySide2.QtWidgets.QTreeWidgetItem.isSelected()
Return type

bool

Returns true if the item is selected, otherwise returns false .

See also

setSelected()

PySide2.QtWidgets.QTreeWidgetItem.__lt__(other)
Parameters

otherQTreeWidgetItem

Return type

bool

PySide2.QtWidgets.QTreeWidgetItem.parent()
Return type

QTreeWidgetItem

Returns the item’s parent.

See also

child()

PySide2.QtWidgets.QTreeWidgetItem.read(in)
Parameters

inQDataStream

Reads the item from stream in . This only reads data into a single item.

See also

write()

PySide2.QtWidgets.QTreeWidgetItem.removeChild(child)
Parameters

childQTreeWidgetItem

Removes the given item indicated by child . The removed item will not be deleted.

PySide2.QtWidgets.QTreeWidgetItem.setBackground(column, brush)
Parameters
  • columnint

  • brushQBrush

Sets the background brush of the label in the given column to the specified brush .

PySide2.QtWidgets.QTreeWidgetItem.setBackgroundColor(column, color)
Parameters
  • columnint

  • colorQColor

Note

This function is deprecated.

This function is deprecated. Use setBackground() instead.

PySide2.QtWidgets.QTreeWidgetItem.setCheckState(column, state)
Parameters
  • columnint

  • stateCheckState

Sets the item in the given column check state to be state .

See also

checkState()

PySide2.QtWidgets.QTreeWidgetItem.setChildIndicatorPolicy(policy)
Parameters

policyChildIndicatorPolicy

Sets the item indicator policy . This policy decides when the tree branch expand/collapse indicator is shown. The default value is ShowForChildren.

PySide2.QtWidgets.QTreeWidgetItem.setData(column, role, value)
Parameters
  • columnint

  • roleint

  • value – object

Sets the value for the item’s column and role to the given value .

The role describes the type of data specified by value , and is defined by the ItemDataRole enum.

Note

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

See also

data()

PySide2.QtWidgets.QTreeWidgetItem.setDisabled(disabled)
Parameters

disabledbool

Disables the item if disabled is true; otherwise enables the item.

PySide2.QtWidgets.QTreeWidgetItem.setExpanded(expand)
Parameters

expandbool

Expands the item if expand is true, otherwise collapses the item.

Warning

The QTreeWidgetItem must be added to the QTreeWidget before calling this function.

See also

isExpanded()

PySide2.QtWidgets.QTreeWidgetItem.setFirstColumnSpanned(span)
Parameters

spanbool

Sets the first section to span all columns if span is true; otherwise all item sections are shown.

PySide2.QtWidgets.QTreeWidgetItem.setFlags(flags)
Parameters

flagsItemFlags

Sets the flags for the item to the given flags . These determine whether the item can be selected or modified. This is often used to disable an item.

See also

flags()

PySide2.QtWidgets.QTreeWidgetItem.setFont(column, font)
Parameters
  • columnint

  • fontQFont

Sets the font used to display the text in the given column to the given font .

PySide2.QtWidgets.QTreeWidgetItem.setForeground(column, brush)
Parameters
  • columnint

  • brushQBrush

Sets the foreground brush of the label in the given column to the specified brush .

PySide2.QtWidgets.QTreeWidgetItem.setHidden(hide)
Parameters

hidebool

Hides the item if hide is true, otherwise shows the item.

Note

A call to this function has no effect if the item is not currently in a view. In particular, calling setHidden(true) on an item and only then adding it to a view will result in a visible item.

See also

isHidden()

PySide2.QtWidgets.QTreeWidgetItem.setIcon(column, icon)
Parameters
  • columnint

  • iconQIcon

Sets the icon to be displayed in the given column to icon .

PySide2.QtWidgets.QTreeWidgetItem.setSelected(select)
Parameters

selectbool

Sets the selected state of the item to select .

See also

isSelected()

PySide2.QtWidgets.QTreeWidgetItem.setSizeHint(column, size)
Parameters
  • columnint

  • sizeQSize

Sets the size hint for the tree item in the given column 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()

PySide2.QtWidgets.QTreeWidgetItem.setStatusTip(column, statusTip)
Parameters
  • columnint

  • statusTip – unicode

Sets the status tip for the given column to the given statusTip . QTreeWidget mouse tracking needs to be enabled for this feature to work.

PySide2.QtWidgets.QTreeWidgetItem.setText(column, text)
Parameters
  • columnint

  • text – unicode

Sets the text to be displayed in the given column to the given text .

PySide2.QtWidgets.QTreeWidgetItem.setTextAlignment(column, alignment)
Parameters
  • columnint

  • alignmentint

Sets the text alignment for the label in the given column to the alignment specified (see AlignmentFlag ).

See also

textAlignment()

PySide2.QtWidgets.QTreeWidgetItem.setTextColor(column, color)
Parameters
  • columnint

  • colorQColor

Note

This function is deprecated.

This function is deprecated. Use setForeground() instead.

See also

textColor()

PySide2.QtWidgets.QTreeWidgetItem.setToolTip(column, toolTip)
Parameters
  • columnint

  • toolTip – unicode

Sets the tooltip for the given column to toolTip .

PySide2.QtWidgets.QTreeWidgetItem.setWhatsThis(column, whatsThis)
Parameters
  • columnint

  • whatsThis – unicode

Sets the “What’s This?” help for the given column to whatsThis .

PySide2.QtWidgets.QTreeWidgetItem.sizeHint(column)
Parameters

columnint

Return type

QSize

Returns the size hint set for the tree item in the given column (see QSize ).

See also

setSizeHint()

PySide2.QtWidgets.QTreeWidgetItem.sortChildren(column, order)
Parameters
  • columnint

  • orderSortOrder

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

Note

This function does nothing if the item is not associated with a QTreeWidget .

PySide2.QtWidgets.QTreeWidgetItem.statusTip(column)
Parameters

columnint

Return type

unicode

Returns the status tip for the contents of the given column .

See also

setStatusTip()

PySide2.QtWidgets.QTreeWidgetItem.takeChild(index)
Parameters

indexint

Return type

QTreeWidgetItem

Removes the item at index and returns it, otherwise return 0.

PySide2.QtWidgets.QTreeWidgetItem.takeChildren()
Return type

Removes the list of children and returns it, otherwise returns an empty list.

PySide2.QtWidgets.QTreeWidgetItem.text(column)
Parameters

columnint

Return type

unicode

Returns the text in the specified column .

See also

setText()

PySide2.QtWidgets.QTreeWidgetItem.textAlignment(column)
Parameters

columnint

Return type

int

Returns the text alignment for the label in the given column (see AlignmentFlag ).

PySide2.QtWidgets.QTreeWidgetItem.textColor(column)
Parameters

columnint

Return type

QColor

Note

This function is deprecated.

This function is deprecated. Use foreground() instead.

See also

setTextColor()

PySide2.QtWidgets.QTreeWidgetItem.toolTip(column)
Parameters

columnint

Return type

unicode

Returns the tool tip for the given column .

See also

setToolTip()

PySide2.QtWidgets.QTreeWidgetItem.treeWidget()
Return type

QTreeWidget

Returns the tree widget that contains the item.

PySide2.QtWidgets.QTreeWidgetItem.type()
Return type

int

Returns the type passed to the QTreeWidgetItem constructor.

PySide2.QtWidgets.QTreeWidgetItem.whatsThis(column)
Parameters

columnint

Return type

unicode

Returns the “What’s This?” help for the contents of the given column .

See also

setWhatsThis()

PySide2.QtWidgets.QTreeWidgetItem.write(out)
Parameters

outQDataStream

Writes the item to stream out . This only writes data from one single item.

See also

read()