Class: QgsTreeWidgetItem

QTreeWidgetItem subclass with custom handling for item sorting.

QgsTreeWidgetItem allows for items to be sorted using a specified user role, and also correctly handles sorting numeric or mixed text and numeric values.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsTreeWidgetItem

Base classes

QTreeWidgetItem

Subclasses

QgsTreeWidgetItemObject

Custom QgsTreeWidgetItem with extra signals when the item is edited.

Methods

alwaysOnTopPriority

Returns the item's priority when it is set to show always on top.

setAlwaysOnTopPriority

Sets a the item to display always on top of other items in the widget, regardless of the sort column and sort or display value for the item.

setSortData

Sets the custom sort data for a specified column.

sortData

Returns the custom sort data for a specified column.

class qgis.gui.QgsTreeWidgetItem[source]

Bases: QTreeWidgetItem

__init__(view: QTreeWidget | None, type: int = QTreeWidgetItem.Type)

Constructor for QgsTreeWidgetItem

Parameters:
  • view (Optional[QTreeWidget]) – parent QTreeWidget view

  • type (int = QTreeWidgetItem.Type) – item type

__init__(type: int = QTreeWidgetItem.Type)

Constructor for QgsTreeWidgetItem

Parameters:

type (int = QTreeWidgetItem.Type) – item type

__init__(strings: Iterable[str | None], type: int = QTreeWidgetItem.Type)

Constructor for QgsTreeWidgetItem

Parameters:
  • strings (Iterable[Optional[str]]) – list of strings containing text for each column in the item

  • type (int = QTreeWidgetItem.Type) – item type

__init__(view: QTreeWidget | None, strings: Iterable[str | None], type: int = QTreeWidgetItem.Type)

Constructor for QgsTreeWidgetItem

Parameters:
  • view (Optional[QTreeWidget]) – parent QTreeWidget view

  • strings (Iterable[Optional[str]]) – list of strings containing text for each column in the item

  • type (int = QTreeWidgetItem.Type) – item type

__init__(view: QTreeWidget | None, after: QTreeWidgetItem | None, type: int = QTreeWidgetItem.Type)

Constructor for QgsTreeWidgetItem

Parameters:
  • view (Optional[QTreeWidget]) – parent QTreeWidget view

  • after (Optional[QTreeWidgetItem]) – QTreeWidgetItem to place insert item after in the view

  • type (int = QTreeWidgetItem.Type) – item type

__init__(parent: QTreeWidgetItem | None, type: int = QTreeWidgetItem.Type)

Constructor for QgsTreeWidgetItem

Parameters:
  • parent (Optional[QTreeWidgetItem]) – QTreeWidgetItem item

  • type (int = QTreeWidgetItem.Type) – item type

__init__(parent: QTreeWidgetItem | None, strings: Iterable[str | None], type: int = QTreeWidgetItem.Type)

Constructor for QgsTreeWidgetItem

Parameters:
  • parent (Optional[QTreeWidgetItem]) – QTreeWidgetItem item

  • strings (Iterable[Optional[str]]) – list of strings containing text for each column in the item

  • type (int = QTreeWidgetItem.Type) – item type

__init__(parent: QTreeWidgetItem | None, after: QTreeWidgetItem | None, type: int = QTreeWidgetItem.Type)

Constructor for QgsTreeWidgetItem

Parameters:
  • parent (Optional[QTreeWidgetItem]) – QTreeWidgetItem item

  • after (Optional[QTreeWidgetItem]) – QTreeWidgetItem to place insert item after in the view

  • type (int = QTreeWidgetItem.Type) – item type

__init__(a0: QgsTreeWidgetItem)
Parameters:

a0 (QgsTreeWidgetItem)

alwaysOnTopPriority(self) int[source]

Returns the item’s priority when it is set to show always on top. Items with a lower priority will be placed above items with a higher priority.

Return type:

int

Returns:

priority, or -1 if item is not set to show always on top

setAlwaysOnTopPriority(self, priority: int)[source]

Sets a the item to display always on top of other items in the widget, regardless of the sort column and sort or display value for the item.

Parameters:

priority (int) – priority for sorting always on top items. Items with a lower priority will be placed above items with a higher priority.

setSortData(self, column: int, value: Any)[source]

Sets the custom sort data for a specified column. If set, this value will be used when sorting the item instead of the item’s display text. If not set, the item’s display text will be used when sorting.

Parameters:
  • column (int) – column index

  • value (Any) – sort value

See also

sortData()

sortData(self, column: int) Any[source]

Returns the custom sort data for a specified column. If set, this value will be used when sorting the item instead of the item’s display text. If not set, the item’s display text will be used when sorting.

See also

setSortData()

Parameters:

column (int)

Return type:

Any