A WTableView displays tabular data. The data is provided by a separate WAbstractItemModel. This is a variation of the classical MVC strategy, where the View displays data provided by a Model. The View delegates the rendering of each individual item (i.e. table cell) to an Item Delegate (WItemDelegate to render an item as a widget, allowing this aspect to be customized without needing to deal with the rest of the complexity of the view.
A more direct approach to showing a table of data is to use a
WTable which allows you to directly specify a widget
that renders each cell. Compared to this, a
support virtual scrolling (for both rows and columns !), column
sorting and resize handles, and the ability to define row
headers which allow you to scroll through many columns of
additional data while keeping the first header column(s) within
view. Its main restriction is that every item must have the same
A tableview has the capability to display large datasets, by implementing virtual scrolling both horizontally and vertically.
The example below shows how one can scroll through data in a virtual model with 10000 rows and 50 columns.
The rendering of each cell is handled by a WAbstractItemDelegate. An item delegate will typically query various properties of an item, which are provided by the model for different data roles (which one can consider pretty much like a 3rd dimension for what otherwise corresponds to two-dimensional model organized in rows and columns). The default implementation (WItemDelegate) will
MVC Views will automatically react to changes to the underlying model, be it in the form of data updates, or the insertion of new rows or columns.
But an MVC View may also actively participate in editing the
data. You can define editing triggers (such as a double click)
and the model can indicate to the view which data can be
edited. The default item delegate (
use a line edit for editing, but this can be customized by
providing your own item delegate implementation.
The example below illustrates how to override the editing behaviour of WItemDelegate. It uses a combo box to allow the user to edit the cell values.
Especially when displaying datasets with many columns, it may be
convenient to define a number of columns as row headers (using
WAbstractItemView::setRowHeaderCount()), which are kept
in view while scrolling to the columns.