Skip to content

PythonQt.QtGui.QTreeWidgetItem

QTreeWidgetItem

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

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:

    QTreeWidgetItem *cities = new QTreeWidgetItem(treeWidget);
    cities->setText(0, tr("Cities"));
    QTreeWidgetItem *osloItem = new 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:

    QTreeWidgetItem *planets = new 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 Qt::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.

Source: https://doc.qt.io/archives/qt-5.15/qtreewidgetitem.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
ChildIndicatorPolicy attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
DontShowIndicator attribute Any
DontShowIndicatorWhenChildless attribute Any
ItemType attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
ShowIndicator attribute Any
Type attribute Any (shared captured text)
UserType attribute Any (shared captured text)
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
addChild function (self, child: Any) -> None Appends the child item to the list of children.
addChildren function (self, children: Any) -> None Appends the given list of children to the item.
background function (self, column: int) -> Any X.background(column) -> PythonQt.QtGui.QBrush
checkState function (self, column: int) -> Any Returns the check state of the label in the given column.
child function (self, index: int) -> Any X.child(index) -> PythonQt.QtGui.QTreeWidgetItem
childCount function (self) -> int X.childCount() -> int
childIndicatorPolicy function (self) -> Any Returns the item indicator policy.
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
clone function (self) -> Any X.clone() -> PythonQt.QtGui.QTreeWidgetItem
columnCount function (self) -> int X.columnCount() -> int
data function (self, column: int, role: int) -> Any X.data(column, role) -> object
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
emitDataChanged function (self) -> None Causes the model associated with this item to emit a [dataChanged](https://doc.qt.io/archives/qt-5.15/qabstractitemmodel.html#dataChanged)() signal for this item.
flags function (self) -> Any Returns the flags used to describe the item.
font function (self, column: int) -> Any X.font(column) -> PythonQt.QtGui.QFont
foreground function (self, column: int) -> Any X.foreground(column) -> PythonQt.QtGui.QBrush
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
icon function (self, column: int) -> Any X.icon(column) -> PythonQt.QtGui.QIcon
indexOfChild function (self, child: Any) -> int X.indexOfChild(child) -> int
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
insertChild function (self, index: int, child: Any) -> None X.insertChild(index, child)
insertChildren function (self, index: int, children: Any) -> None X.insertChildren(index, children)
isDisabled function (self) -> bool X.isDisabled() -> bool
isExpanded function (self) -> bool X.isExpanded() -> bool
isFirstColumnSpanned function (self) -> bool X.isFirstColumnSpanned() -> bool
isHidden function (self) -> bool X.isHidden() -> bool
isSelected function (self) -> bool X.isSelected() -> bool
parent function (self) -> Any X.parent() -> PythonQt.QtGui.QTreeWidgetItem
read function (self, *args: Any, **kwargs: Any) -> None Reads the item from stream in.
readFrom function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
removeChild function (self, child: Any) -> None Removes the given item indicated by child.
setBackground function (self, column: int, brush: Any) -> None X.setBackground(column, brush)
setCheckState function (self, column: int, state: Any) -> None X.setCheckState(column, state)
setChildIndicatorPolicy function (self, policy: Any) -> None Sets the item indicator policy.
setData function (self, column: int, role: int, value: Any) -> None X.setData(column, role, value)
setDisabled function (self, disabled: bool) -> None Disables the item if disabled is true; otherwise enables the item.
setExpanded function (self, expand: bool) -> None Expands the item if expand is true, otherwise collapses the item.
setFirstColumnSpanned function (self, span: bool) -> None Sets the first section to span all columns if span is true; otherwise all item sections are shown.
setFlags function (self, arg0: flags) -> None Sets the flags for the item to the given flags.
setFont function (self, column: int, font: Any) -> None X.setFont(column, font)
setForeground function (self, column: int, brush: Any) -> None X.setForeground(column, brush)
setHidden function (self, hide: bool) -> None Hides the item if hide is true, otherwise shows the item.
setIcon function (self, column: int, icon: Any) -> None X.setIcon(column, icon)
setSelected function (self, select: bool) -> None Sets the selected state of the item to select.
setSizeHint function (self, column: int, size: Any) -> None X.setSizeHint(column, size)
setStatusTip function (self, column: int, statusTip: str) -> None X.setStatusTip(column, statusTip)
setText function (self, column: int, text: str) -> None X.setText(column, text)
setTextAlignment function (self, column: int, alignment: int) -> None X.setTextAlignment(column, alignment)
setToolTip function (self, column: int, toolTip: str) -> None X.setToolTip(column, toolTip)
setWhatsThis function (self, column: int, whatsThis: str) -> None X.setWhatsThis(column, whatsThis)
sizeHint function (self, column: int) -> Any X.sizeHint(column) -> PythonQt.QtCore.QSize
sortChildren function (self, column: int, order: Any) -> None X.sortChildren(column, order)
statusTip function (self, column: int) -> str X.statusTip(column) -> str
takeChild function (self, index: int) -> Any X.takeChild(index) -> PythonQt.QtGui.QTreeWidgetItem
takeChildren function (self) -> tuple X.takeChildren() -> tuple
text function (self, column: int) -> str X.text(column) -> str
textAlignment function (self, column: int) -> int X.textAlignment(column) -> int
toolTip function (self, column: int) -> str X.toolTip(column) -> str
treeWidget function (self) -> Any X.treeWidget() -> PythonQt.QtGui.QTreeWidget
type function (self) -> int X.type() -> int
whatsThis function (self, column: int) -> str X.whatsThis(column) -> str
write function (self, out: Any) -> None Writes the item to stream out.
writeTo function (self, out: Any) -> Any (shared captured text)