TreeView:
Filter:
Classes | GUI > Views

TreeView : View : QObject : Object

A view displaying a tree of items with columns
Source: QTreeView.sc
Subclasses: QTreeView

Description

A view that displays a hierarchy of items. It is divided into rows and column: each row represents an item, and each column represents a different data field of the items.

The items are represented in code by instances of TreeViewItem, returned by the various TreeView methods. Top level items are added via the TreeView interface, while child items are added via the TreeViewItem interface, which also allows to manipulate items in more detail after their creation.

Items can be visually sorted with -sort, or by clicking on one of the column headers, if -canSort is enabled.

Each item can hold other views in each of its data fields, which allows for rich graphical interaction. See TreeViewItem: -setView.

Class Methods

Inherited class methods

Undocumented class methods

TreeView.qtClass

Instance Methods

Data

.columns

.columns = labels

Gets or sets the number of columns (data fields) and their names. When setting a smaller number of columns than the current the extra columns will be removed, and hence all the data stored stored in those columns.

Arguments:

labels

An array of Strings for column names.

.numColumns

The total number of columns (data fields).

.addItem(strings)

Append a new top-level item.

Arguments:

strings

An array of Strings (or nil), each for the text of one data field.

Returns:

An instance of TreeViewItem representing the new item.

.insertItem(index, strings)

Insert a new top-level item at index.

Arguments:

index

The position at which to insert the item.

strings

An array of Strings (or nil), each for the text of one data field.

Returns:

An instance of TreeViewItem representing the new item.

.removeItem(item)

Remove the given item. After the item is removed, any usage of the related TreeViewItems will have no effect.

Arguments:

item

An instance of TreeViewItem.

.numItems

The total number of items.

.clear

Removes all items.

.currentItem

.currentItem = item

Gets or sets the currently selected item.

Arguments:

item

An instance of TreeViewItem.

Returns:

An instance of TreeViewItem or nil, if no current item.

.itemAt(index)

The item at index.

.childAt(index)

Alias for -itemAt, provided for compatibility with TreeViewItem.

.addChild(strings)

Alias for -addItem, provided for compatibility with TreeViewItem.

.insertChild(index, strings)

Alias for -addChild, provided for compatibility with TreeViewItem.

Appearance

.sort(column, descending: false)

Sort items by data in column. This works regardless of -canSort.

NOTE: Sorting has no effect on the logical order of the items, it only affects how they are displayed.

Arguments:

column

The integer column index to sort by.

descending

Whether to sort in descending or ascending fashion. The default is ascending.

.columnWidth(column)

Arguments:

column

The integer index of a column

Returns:

Integer width of column in pixels. If column is not in the range 0..(numColumns-1), returns -1.

.setColumnWidth(column, width)

Sets the width of a column. The rightmost column must extend at least to the right bound of the TreeView.

Arguments:

column

The integer index of the column to modify

width

Integer width in pixels

Interaction

.canSort

.canSort = bool

Whether the user can sort the items by clicking on a column header.

When setting to true, the items will be sorted immediately according to the current sorting column. While true, the view will also automatically sort new items.

The default is false.

See also: -sort.

Actions

.itemPressedAction

.itemPressedAction = action

The object to be evaluated when a mouse button is pressed on an item, passing this view as the argument.

.onItemChanged

.onItemChanged = hook

The object to be evaluated whenever the current item changes, passing this view as the argument.

Inherited instance methods

Examples