|  | Home · Overviews · Examples |

# QAbstractItemView Class Reference
[com.trolltech.qt.gui module]

The `QAbstractItemView` class provides the basic functionality for item view classes. More...

Inherits `QAbstractScrollArea`.

Inherited by `QColumnView`, `QHeaderView`, `QListView`, `QTableView`, and `QTreeView`.

## Detailed Description

The `QAbstractItemView` class provides the basic functionality for item view classes.

`QAbstractItemView` class is the base class for every standard view that uses a `QAbstractItemModel`. `QAbstractItemView` is an abstract class and cannot itself be instantiated. It provides a standard interface for interoperating with models through the signals and slots mechanism, enabling subclasses to be kept up-to-date with changes to their models. This class provides standard support for keyboard and mouse navigation, viewport scrolling, item editing, and selections.

The `QAbstractItemView` class is one of the Model/View Classes and is part of Qt's model/view framework.

The view classes that inherit `QAbstractItemView` only need to implement their own view-specific functionality, such as drawing items, returning the geometry of items, finding items, etc.

`QAbstractItemView` provides common slots such as `edit` and `setCurrentIndex`. Many protected slots are also provided, including `dataChanged`, `rowsInserted`, `rowsAboutToBeRemoved`, `selectionChanged`, and `currentChanged`.

The root item is returned by `rootIndex`, and the current item by `currentIndex`. To make sure that an item is visible use `scrollTo`.

Some of `QAbstractItemView`'s functions are concerned with scrolling, for example `setHorizontalScrollMode` and `setVerticalScrollMode`. To set the range of the scroll bars, you can, for example, reimplement the view's `resizeEvent` function:

        void MyView::resizeEvent(QResizeEvent *event) {
            horizontalScrollBar()->setRange(0, realWidth - width());
            ...
        }

Note that the range is not updated until the widget is shown.

Several other functions are concerned with selection control; for example `setSelectionMode`, and `setSelectionBehavior`. This class provides a default selection model to work with (`selectionModel`), but this can be replaced by using `setSelectionModel` with an instance of `QItemSelectionModel`.

For complete control over the display and editing of items you can specify a delegate with `setItemDelegate`.

`QAbstractItemView` provides a lot of protected functions. Some are concerned with editing, for example, `edit`, and `commitData`, whilst others are keyboard and mouse event handlers.

See also View Classes, Model/View Programming, `QAbstractItemModel`, and Chart Example.