Class WTreeView


public class WTreeView
extends WAbstractItemView
A view class that displays a model as a tree or tree table.

The view displays data from a WAbstractItemModel in a tree or tree table. It provides incremental rendering, allowing the display of data models of any size efficiently, without excessive use of client- or serverside resources.

The rendering (and editing) of items is handled by a WAbstractItemDelegate, by default it uses WItemDelegate which renders data of all predefined roles (see also ItemDataRole), including text, icons, checkboxes, and tooltips.

The view may support editing of items, if the model indicates support (see the ItemFlag.Editable flag). You can define triggers that initiate editing of an item using WAbstractItemView#setEditTriggers(). The actual editing is provided by the item delegate (you can set an appropriate delegate for one column using WAbstractItemView#setItemDelegateForColumn()). Using WAbstractItemView#setEditOptions() you can customize if and how the view deals with multiple editors.

By default, all but the first columns are given a width of 150px, and the first column takes the remaining size. Note that this may have as consequence that the first column's size is reduced to 0. Column widths of all columns, including the first column, can be set through the API method setColumnWidth(), and also by the user using handles provided in the header.

Optionally, the treeview may be configured so that the first column is always visible while scrolling through the other columns, which may be convenient if you wish to display a model with many columns. Use setColumn1Fixed() to enable this behaviour.

If the model supports sorting (WAbstractItemModel#sort()), such as the WStandardItemModel, then you can enable sorting buttons in the header, using WAbstractItemView#setSortingEnabled().

You can allow selection on row or item level (using WAbstractItemView#setSelectionBehavior()), and selection of single or multiple items (using WAbstractItemView#setSelectionMode()), and listen for changes in the selection using the WAbstractItemView.selectionChanged() signal.

You may enable drag & drop support for this view, with awareness of the items in the model. When enabling dragging (see WAbstractItemView#setDragEnabled()), the current selection may be dragged, but only when all items in the selection indicate support for dragging (controlled by the ItemFlag.DragEnabled flag), and if the model indicates a mime-type (controlled by WAbstractItemModel.getMimeType()). Likewise, by enabling support for dropping (see WAbstractItemView#setDropsEnabled()), the treeview may receive a drop event on a particular item, at least if the item indicates support for drops (controlled by the ItemFlag.DropEnabled flag).

You may also react to mouse click events on any item, by connecting to one of the WAbstractItemView.clicked() or WAbstractItemView.doubleClicked() signals.

Graceful degradation

The view provides a virtual scrolling behavior which relies on Ajax availability. When Ajax is not available, a page navigation bar is used instead, see WAbstractItemView.getCreatePageNavigationBar(). In that case, the widget needs to be given an explicit height using resize() which determines the number of rows that are displayed at a time.

A snapshot of the WTreeView:

WTreeView example (default)

WTreeView example (polished)