QTreeWidgetItem

Inheritance diagram of PySide2.QtWidgets.QTreeWidgetItem

Synopsis

Functions

Virtual functions

Detailed Description

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

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 PySide2.QtWidgets.QTreeWidgetItem class is a convenience class that replaces the QListViewItem class in Qt 3. It provides an item for use with the PySide2.QtWidgets.QTreeWidget class.

Items are usually constructed with a parent that is either a PySide2.QtWidgets.QTreeWidget (for top-level items) or a PySide2.QtWidgets.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 PySide2.QtWidgets.QTreeWidgetItem.setBackground() function. The current background brush can be found with PySide2.QtWidgets.QTreeWidgetItem.background() . The text label for each column can be rendered with its own font and brush. These are specified with the PySide2.QtWidgets.QTreeWidgetItem.setFont() and PySide2.QtWidgets.QTreeWidgetItem.setForeground() functions, and read with PySide2.QtWidgets.QTreeWidgetItem.font() and PySide2.QtWidgets.QTreeWidgetItem.foreground() .

The main difference between top-level items and those in lower levels of the tree is that a top-level item has no PySide2.QtWidgets.QTreeWidgetItem.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 PySide2.QtWidgets.QTreeWidgetItem.takeChild() and inserted at a given index in the list of children with the PySide2.QtWidgets.QTreeWidgetItem.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 PySide2.QtWidgets.QTreeWidgetItem.setFlags() with the appropriate value (see Qt.ItemFlags ). Checkable items can be checked and unchecked with the PySide2.QtWidgets.QTreeWidgetItem.setCheckState() function. The corresponding PySide2.QtWidgets.QTreeWidgetItem.checkState() function indicates whether the item is currently checked.

Subclassing

When subclassing PySide2.QtWidgets.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 PySide2.QtWidgets.QTreeWidgetItem(view, after[, type=Type])
class PySide2.QtWidgets.QTreeWidgetItem(view, strings[, type=Type])
class PySide2.QtWidgets.QTreeWidgetItem(view[, type=Type])
class PySide2.QtWidgets.QTreeWidgetItem(parent, after[, type=Type])
class PySide2.QtWidgets.QTreeWidgetItem(parent, strings[, type=Type])
class PySide2.QtWidgets.QTreeWidgetItem(parent[, type=Type])
class PySide2.QtWidgets.QTreeWidgetItem(strings[, type=Type])
class PySide2.QtWidgets.QTreeWidgetItem(other)
class PySide2.QtWidgets.QTreeWidgetItem([type=Type])
Parameters:

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

Constructs a tree widget item of the specified type and appends it to the items in the given parent . The given list of strings will be set as the item text for each column in the item.

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

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

Constructs a tree widget item and append it to the given parent . The given list of strings will be set as the item text for each column in the item.

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

Constructs a tree widget item of the specified type . The item must be inserted into a tree widget. The given list of strings will be set as the item text for each column in the item.

Constructs a copy of other . Note that PySide2.QtWidgets.QTreeWidgetItem.type() and PySide2.QtWidgets.QTreeWidgetItem.treeWidget() are not copied.

This function is useful when reimplementing PySide2.QtWidgets.QTreeWidgetItem.clone() .

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

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 PySide2.QtWidgets.QTreeWidgetItem subclasses to ensure that custom items are treated specially; for example, when items are sorted.

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:childPySide2.QtWidgets.QTreeWidgetItem

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:columnPySide2.QtCore.int
Return type:PySide2.QtGui.QBrush

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

PySide2.QtWidgets.QTreeWidgetItem.backgroundColor(column)
Parameters:columnPySide2.QtCore.int
Return type:PySide2.QtGui.QColor

This function is deprecated. Use PySide2.QtWidgets.QTreeWidgetItem.background() instead.

PySide2.QtWidgets.QTreeWidgetItem.checkState(column)
Parameters:columnPySide2.QtCore.int
Return type:PySide2.QtCore.Qt.CheckState

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

PySide2.QtWidgets.QTreeWidgetItem.child(index)
Parameters:indexPySide2.QtCore.int
Return type:PySide2.QtWidgets.QTreeWidgetItem

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

PySide2.QtWidgets.QTreeWidgetItem.childCount()
Return type:PySide2.QtCore.int

Returns the number of child items.

PySide2.QtWidgets.QTreeWidgetItem.childIndicatorPolicy()
Return type:PySide2.QtWidgets.QTreeWidgetItem.ChildIndicatorPolicy

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

PySide2.QtWidgets.QTreeWidgetItem.clone()
Return type:PySide2.QtWidgets.QTreeWidgetItem

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

PySide2.QtWidgets.QTreeWidgetItem.columnCount()
Return type:PySide2.QtCore.int

Returns the number of columns in the item.

PySide2.QtWidgets.QTreeWidgetItem.data(column, role)
Parameters:
  • columnPySide2.QtCore.int
  • rolePySide2.QtCore.int
Return type:

object

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

PySide2.QtWidgets.QTreeWidgetItem.emitDataChanged()

Causes the model associated with this item to emit a PySide2.QtCore.QAbstractItemModel.dataChanged() () signal for this item.

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

PySide2.QtWidgets.QTreeWidgetItem.flags()
Return type:PySide2.QtCore.Qt.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 Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled | Qt.ItemIsDropEnabled .

PySide2.QtWidgets.QTreeWidgetItem.font(column)
Parameters:columnPySide2.QtCore.int
Return type:PySide2.QtGui.QFont

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

PySide2.QtWidgets.QTreeWidgetItem.foreground(column)
Parameters:columnPySide2.QtCore.int
Return type:PySide2.QtGui.QBrush

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

PySide2.QtWidgets.QTreeWidgetItem.icon(column)
Parameters:columnPySide2.QtCore.int
Return type:PySide2.QtGui.QIcon

Returns the icon that is displayed in the specified column .

PySide2.QtWidgets.QTreeWidgetItem.indexOfChild(child)
Parameters:childPySide2.QtWidgets.QTreeWidgetItem
Return type:PySide2.QtCore.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:
  • indexPySide2.QtCore.int
  • 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:PySide2.QtCore.bool

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

PySide2.QtWidgets.QTreeWidgetItem.isExpanded()
Return type:PySide2.QtCore.bool

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

PySide2.QtWidgets.QTreeWidgetItem.isFirstColumnSpanned()
Return type:PySide2.QtCore.bool

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

PySide2.QtWidgets.QTreeWidgetItem.isHidden()
Return type:PySide2.QtCore.bool

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

PySide2.QtWidgets.QTreeWidgetItem.isSelected()
Return type:PySide2.QtCore.bool

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

PySide2.QtWidgets.QTreeWidgetItem.__lt__(other)
Parameters:otherPySide2.QtWidgets.QTreeWidgetItem
Return type:PySide2.QtCore.bool

Returns true if the text in the item is less than the text in the other item, otherwise returns false .

PySide2.QtWidgets.QTreeWidgetItem.parent()
Return type:PySide2.QtWidgets.QTreeWidgetItem

Returns the item’s parent.

PySide2.QtWidgets.QTreeWidgetItem.read(in)
Parameters:inPySide2.QtCore.QDataStream

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

PySide2.QtWidgets.QTreeWidgetItem.removeChild(child)
Parameters:childPySide2.QtWidgets.QTreeWidgetItem

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

PySide2.QtWidgets.QTreeWidgetItem.setBackground(column, brush)
Parameters:

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

PySide2.QtWidgets.QTreeWidgetItem.setBackgroundColor(column, color)
Parameters:

This function is deprecated. Use PySide2.QtWidgets.QTreeWidgetItem.setBackground() instead.

PySide2.QtWidgets.QTreeWidgetItem.setCheckState(column, state)
Parameters:
  • columnPySide2.QtCore.int
  • statePySide2.QtCore.Qt.CheckState

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

PySide2.QtWidgets.QTreeWidgetItem.setChildIndicatorPolicy(policy)
Parameters:policyPySide2.QtWidgets.QTreeWidgetItem.ChildIndicatorPolicy

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:
  • columnPySide2.QtCore.int
  • rolePySide2.QtCore.int
  • 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 Qt.ItemDataRole enum.

Note

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

PySide2.QtWidgets.QTreeWidgetItem.setDisabled(disabled)
Parameters:disabledPySide2.QtCore.bool

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

PySide2.QtWidgets.QTreeWidgetItem.setExpanded(expand)
Parameters:expandPySide2.QtCore.bool

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

Warning

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

PySide2.QtWidgets.QTreeWidgetItem.setFirstColumnSpanned(span)
Parameters:spanPySide2.QtCore.bool

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

PySide2.QtWidgets.QTreeWidgetItem.setFlags(flags)
Parameters:flagsPySide2.QtCore.Qt.ItemFlags

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.

PySide2.QtWidgets.QTreeWidgetItem.setFont(column, font)
Parameters:

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

PySide2.QtWidgets.QTreeWidgetItem.setForeground(column, brush)
Parameters:

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

PySide2.QtWidgets.QTreeWidgetItem.setHidden(hide)
Parameters:hidePySide2.QtCore.bool

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.

PySide2.QtWidgets.QTreeWidgetItem.setIcon(column, icon)
Parameters:

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

PySide2.QtWidgets.QTreeWidgetItem.setSelected(select)
Parameters:selectPySide2.QtCore.bool

Sets the selected state of the item to select .

PySide2.QtWidgets.QTreeWidgetItem.setSizeHint(column, size)
Parameters:

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.

PySide2.QtWidgets.QTreeWidgetItem.setStatusTip(column, statusTip)
Parameters:
  • columnPySide2.QtCore.int
  • statusTip – unicode

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

PySide2.QtWidgets.QTreeWidgetItem.setText(column, text)
Parameters:
  • columnPySide2.QtCore.int
  • text – unicode

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

PySide2.QtWidgets.QTreeWidgetItem.setTextAlignment(column, alignment)
Parameters:
  • columnPySide2.QtCore.int
  • alignmentPySide2.QtCore.int

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

PySide2.QtWidgets.QTreeWidgetItem.setTextColor(column, color)
Parameters:

This function is deprecated. Use PySide2.QtWidgets.QTreeWidgetItem.setForeground() instead.

PySide2.QtWidgets.QTreeWidgetItem.setToolTip(column, toolTip)
Parameters:
  • columnPySide2.QtCore.int
  • toolTip – unicode

Sets the tooltip for the given column to toolTip .

PySide2.QtWidgets.QTreeWidgetItem.setWhatsThis(column, whatsThis)
Parameters:
  • columnPySide2.QtCore.int
  • whatsThis – unicode

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

PySide2.QtWidgets.QTreeWidgetItem.sizeHint(column)
Parameters:columnPySide2.QtCore.int
Return type:PySide2.QtCore.QSize

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

PySide2.QtWidgets.QTreeWidgetItem.sortChildren(column, order)
Parameters:
  • columnPySide2.QtCore.int
  • orderPySide2.QtCore.Qt.SortOrder

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 PySide2.QtWidgets.QTreeWidget .

PySide2.QtWidgets.QTreeWidgetItem.statusTip(column)
Parameters:columnPySide2.QtCore.int
Return type:unicode

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

PySide2.QtWidgets.QTreeWidgetItem.takeChild(index)
Parameters:indexPySide2.QtCore.int
Return type:PySide2.QtWidgets.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:columnPySide2.QtCore.int
Return type:unicode

Returns the text in the specified column .

PySide2.QtWidgets.QTreeWidgetItem.textAlignment(column)
Parameters:columnPySide2.QtCore.int
Return type:PySide2.QtCore.int

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

PySide2.QtWidgets.QTreeWidgetItem.textColor(column)
Parameters:columnPySide2.QtCore.int
Return type:PySide2.QtGui.QColor

This function is deprecated. Use PySide2.QtWidgets.QTreeWidgetItem.foreground() instead.

PySide2.QtWidgets.QTreeWidgetItem.toolTip(column)
Parameters:columnPySide2.QtCore.int
Return type:unicode

Returns the tool tip for the given column .

PySide2.QtWidgets.QTreeWidgetItem.treeWidget()
Return type:PySide2.QtWidgets.QTreeWidget

Returns the tree widget that contains the item.

PySide2.QtWidgets.QTreeWidgetItem.type()
Return type:PySide2.QtCore.int

Returns the type passed to the PySide2.QtWidgets.QTreeWidgetItem constructor.

PySide2.QtWidgets.QTreeWidgetItem.whatsThis(column)
Parameters:columnPySide2.QtCore.int
Return type:unicode

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

PySide2.QtWidgets.QTreeWidgetItem.write(out)
Parameters:outPySide2.QtCore.QDataStream

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