QTreeWidgetItem

Synopsis

Functions

Virtual functions

Detailed Description

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

Items are usually constructed with a parent that is either a PySide.QtGui.QTreeWidget (for top-level items) or a PySide.QtGui.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 PySide.QtGui.QTreeWidgetItem.setBackground() function. The current background brush can be found with PySide.QtGui.QTreeWidgetItem.background() . The text label for each column can be rendered with its own font and brush. These are specified with the PySide.QtGui.QTreeWidgetItem.setFont() and PySide.QtGui.QTreeWidgetItem.setForeground() functions, and read with PySide.QtGui.QTreeWidgetItem.font() and PySide.QtGui.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 PySide.QtGui.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 PySide.QtGui.QTreeWidgetItem.takeChild() and inserted at a given index in the list of children with the PySide.QtGui.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 PySide.QtGui.QTreeWidgetItem.setFlags() with the appropriate value (see Qt.ItemFlags ). Checkable items can be checked and unchecked with the PySide.QtGui.QTreeWidgetItem.setCheckState() function. The corresponding PySide.QtGui.QTreeWidgetItem.checkState() function indicates whether the item is currently checked.

Subclassing

When subclassing PySide.QtGui.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 PySide.QtGui.QTreeWidgetItem(view, after[, type=Type])
class PySide.QtGui.QTreeWidgetItem(view, strings[, type=Type])
class PySide.QtGui.QTreeWidgetItem(view[, type=Type])
class PySide.QtGui.QTreeWidgetItem(parent, after[, type=Type])
class PySide.QtGui.QTreeWidgetItem(parent, strings[, type=Type])
class PySide.QtGui.QTreeWidgetItem(parent[, type=Type])
class PySide.QtGui.QTreeWidgetItem(strings[, type=Type])
class PySide.QtGui.QTreeWidgetItem(other)
class PySide.QtGui.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 PySide.QtGui.QTreeWidgetItem.type() and PySide.QtGui.QTreeWidgetItem.treeWidget() are not copied.

This function is useful when reimplementing PySide.QtGui.QTreeWidgetItem.clone() .

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

PySide.QtGui.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 UserType are reserved by Qt.

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

PySide.QtGui.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.
PySide.QtGui.QTreeWidgetItem.addChild(child)
Parameters:childPySide.QtGui.QTreeWidgetItem

Appends the child item to the list of children.

PySide.QtGui.QTreeWidgetItem.addChildren(children)
Parameters:children
PySide.QtGui.QTreeWidgetItem.background(column)
Parameters:columnPySide.QtCore.int
Return type:PySide.QtGui.QBrush

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

PySide.QtGui.QTreeWidgetItem.checkState(column)
Parameters:columnPySide.QtCore.int
Return type:PySide.QtCore.Qt.CheckState

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

PySide.QtGui.QTreeWidgetItem.child(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtGui.QTreeWidgetItem

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

PySide.QtGui.QTreeWidgetItem.childCount()
Return type:PySide.QtCore.int

Returns the number of child items.

PySide.QtGui.QTreeWidgetItem.childIndicatorPolicy()
Return type:PySide.QtGui.QTreeWidgetItem.ChildIndicatorPolicy

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

PySide.QtGui.QTreeWidgetItem.childrenCheckState(column)
Parameters:columnPySide.QtCore.int
Return type:object
PySide.QtGui.QTreeWidgetItem.clone()
Return type:PySide.QtGui.QTreeWidgetItem

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

PySide.QtGui.QTreeWidgetItem.columnCount()
Return type:PySide.QtCore.int

Returns the number of columns in the item.

PySide.QtGui.QTreeWidgetItem.data(column, role)
Parameters:
  • columnPySide.QtCore.int
  • rolePySide.QtCore.int
Return type:

object

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

PySide.QtGui.QTreeWidgetItem.emitDataChanged()

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

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

PySide.QtGui.QTreeWidgetItem.executePendingSort()
PySide.QtGui.QTreeWidgetItem.flags()
Return type:PySide.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 . If the item was constructed with a parent, flags will in addition contain Qt.ItemIsDropEnabled .

PySide.QtGui.QTreeWidgetItem.font(column)
Parameters:columnPySide.QtCore.int
Return type:PySide.QtGui.QFont

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

PySide.QtGui.QTreeWidgetItem.foreground(column)
Parameters:columnPySide.QtCore.int
Return type:PySide.QtGui.QBrush

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

PySide.QtGui.QTreeWidgetItem.icon(column)
Parameters:columnPySide.QtCore.int
Return type:PySide.QtGui.QIcon

Returns the icon that is displayed in the specified column .

PySide.QtGui.QTreeWidgetItem.indexOfChild(child)
Parameters:childPySide.QtGui.QTreeWidgetItem
Return type:PySide.QtCore.int

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

PySide.QtGui.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 wont be inserted again.

PySide.QtGui.QTreeWidgetItem.insertChildren(index, children)
Parameters:
  • indexPySide.QtCore.int
  • children
PySide.QtGui.QTreeWidgetItem.isDisabled()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTreeWidgetItem.isExpanded()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTreeWidgetItem.isFirstColumnSpanned()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTreeWidgetItem.isHidden()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTreeWidgetItem.isSelected()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTreeWidgetItem.itemChanged()
PySide.QtGui.QTreeWidgetItem.__lt__(other)
Parameters:otherPySide.QtGui.QTreeWidgetItem
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTreeWidgetItem.parent()
Return type:PySide.QtGui.QTreeWidgetItem

Returns the item’s parent.

PySide.QtGui.QTreeWidgetItem.read(in)
Parameters:inPySide.QtCore.QDataStream

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

PySide.QtGui.QTreeWidgetItem.removeChild(child)
Parameters:childPySide.QtGui.QTreeWidgetItem

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

PySide.QtGui.QTreeWidgetItem.setBackground(column, brush)
Parameters:

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

PySide.QtGui.QTreeWidgetItem.setCheckState(column, state)
Parameters:
  • columnPySide.QtCore.int
  • statePySide.QtCore.Qt.CheckState
PySide.QtGui.QTreeWidgetItem.setChildIndicatorPolicy(policy)
Parameters:policyPySide.QtGui.QTreeWidgetItem.ChildIndicatorPolicy
PySide.QtGui.QTreeWidgetItem.setData(column, role, value)
Parameters:
  • columnPySide.QtCore.int
  • rolePySide.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.

PySide.QtGui.QTreeWidgetItem.setDisabled(disabled)
Parameters:disabledPySide.QtCore.bool

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

PySide.QtGui.QTreeWidgetItem.setExpanded(expand)
Parameters:expandPySide.QtCore.bool

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

Warning

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

PySide.QtGui.QTreeWidgetItem.setFirstColumnSpanned(span)
Parameters:spanPySide.QtCore.bool

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

PySide.QtGui.QTreeWidgetItem.setFlags(flags)
Parameters:flagsPySide.QtCore.Qt.ItemFlags
PySide.QtGui.QTreeWidgetItem.setFont(column, font)
Parameters:

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

PySide.QtGui.QTreeWidgetItem.setForeground(column, brush)
Parameters:

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

PySide.QtGui.QTreeWidgetItem.setHidden(hide)
Parameters:hidePySide.QtCore.bool

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

PySide.QtGui.QTreeWidgetItem.setIcon(column, icon)
Parameters:

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

PySide.QtGui.QTreeWidgetItem.setSelected(select)
Parameters:selectPySide.QtCore.bool

Sets the selected state of the item to select .

PySide.QtGui.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.

PySide.QtGui.QTreeWidgetItem.setStatusTip(column, statusTip)
Parameters:
  • columnPySide.QtCore.int
  • statusTip – unicode

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

PySide.QtGui.QTreeWidgetItem.setText(column, text)
Parameters:
  • columnPySide.QtCore.int
  • text – unicode

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

PySide.QtGui.QTreeWidgetItem.setTextAlignment(column, alignment)
Parameters:
  • columnPySide.QtCore.int
  • alignmentPySide.QtCore.int

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

PySide.QtGui.QTreeWidgetItem.setToolTip(column, toolTip)
Parameters:
  • columnPySide.QtCore.int
  • toolTip – unicode

Sets the tooltip for the given column to toolTip .

PySide.QtGui.QTreeWidgetItem.setWhatsThis(column, whatsThis)
Parameters:
  • columnPySide.QtCore.int
  • whatsThis – unicode

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

PySide.QtGui.QTreeWidgetItem.sizeHint(column)
Parameters:columnPySide.QtCore.int
Return type:PySide.QtCore.QSize

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

PySide.QtGui.QTreeWidgetItem.sortChildren(column, order)
Parameters:
  • columnPySide.QtCore.int
  • orderPySide.QtCore.Qt.SortOrder
PySide.QtGui.QTreeWidgetItem.sortChildren(column, order, climb)
Parameters:
  • columnPySide.QtCore.int
  • orderPySide.QtCore.Qt.SortOrder
  • climbPySide.QtCore.bool
PySide.QtGui.QTreeWidgetItem.statusTip(column)
Parameters:columnPySide.QtCore.int
Return type:unicode

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

PySide.QtGui.QTreeWidgetItem.takeChild(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtGui.QTreeWidgetItem

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

PySide.QtGui.QTreeWidgetItem.takeChildren()
Return type:

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

PySide.QtGui.QTreeWidgetItem.text(column)
Parameters:columnPySide.QtCore.int
Return type:unicode

Returns the text in the specified column .

PySide.QtGui.QTreeWidgetItem.textAlignment(column)
Parameters:columnPySide.QtCore.int
Return type:PySide.QtCore.int

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

PySide.QtGui.QTreeWidgetItem.toolTip(column)
Parameters:columnPySide.QtCore.int
Return type:unicode

Returns the tool tip for the given column .

PySide.QtGui.QTreeWidgetItem.treeWidget()
Return type:PySide.QtGui.QTreeWidget

Returns the tree widget that contains the item.

PySide.QtGui.QTreeWidgetItem.type()
Return type:PySide.QtCore.int

Returns the type passed to the PySide.QtGui.QTreeWidgetItem constructor.

PySide.QtGui.QTreeWidgetItem.whatsThis(column)
Parameters:columnPySide.QtCore.int
Return type:unicode

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

PySide.QtGui.QTreeWidgetItem.write(out)
Parameters:outPySide.QtCore.QDataStream

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