|  | Home · All Classes · Modules

# QAbstractItemView Class Reference
[QtGui module]

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

Inherits QAbstractScrollArea.

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

### Types

- enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight, ..., MovePrevious }
- enum DragDropMode { NoDragDrop, DragOnly, DropOnly, DragDrop, InternalMove }
- enum DropIndicatorPosition { OnItem, AboveItem, BelowItem, OnViewport }
- enum EditTrigger { NoEditTriggers, CurrentChanged, DoubleClicked, SelectedClicked, ..., AllEditTriggers }
- class EditTriggers
- enum ScrollHint { EnsureVisible, PositionAtTop, PositionAtBottom, PositionAtCenter }
- enum ScrollMode { ScrollPerItem, ScrollPerPixel }
- enum SelectionBehavior { SelectItems, SelectRows, SelectColumns }
- enum SelectionMode { NoSelection, SingleSelection, MultiSelection, ExtendedSelection, ContiguousSelection }
- enum State { NoState, DraggingState, DragSelectingState, EditingState, ..., AnimatingState }

### Methods

- __init__ (self, QWidget parent = None)
- bool alternatingRowColors (self)
- int autoScrollMargin (self)
- clearSelection (self)
- closeEditor (self, QWidget, QAbstractItemDelegate.EndEditHint)
- closePersistentEditor (self, QModelIndex)
- commitData (self, QWidget)
- currentChanged (self, QModelIndex, QModelIndex)
- QModelIndex currentIndex (self)
- dataChanged (self, QModelIndex, QModelIndex)
- Qt.DropAction defaultDropAction (self)
- QPoint dirtyRegionOffset (self)
- doItemsLayout (self)
- DragDropMode dragDropMode (self)
- bool dragDropOverwriteMode (self)
- bool dragEnabled (self)
- dragEnterEvent (self, QDragEnterEvent)
- dragLeaveEvent (self, QDragLeaveEvent)
- dragMoveEvent (self, QDragMoveEvent)
- dropEvent (self, QDropEvent)
- DropIndicatorPosition dropIndicatorPosition (self)
- edit (self, QModelIndex)
- bool edit (self, QModelIndex, EditTrigger, QEvent)
- editorDestroyed (self, QObject)
- EditTriggers editTriggers (self)
- bool event (self, QEvent)
- executeDelayedItemsLayout (self)
- focusInEvent (self, QFocusEvent)
- bool focusNextPrevChild (self, bool)
- focusOutEvent (self, QFocusEvent)
- bool hasAutoScroll (self)
- int horizontalOffset (self)
- horizontalScrollbarAction (self, int)
- horizontalScrollbarValueChanged (self, int)
- ScrollMode horizontalScrollMode (self)
- int horizontalStepsPerItem (self)
- QSize iconSize (self)
- QModelIndex indexAt (self, QPoint)
- QWidget indexWidget (self, QModelIndex)
- inputMethodEvent (self, QInputMethodEvent)
- QVariant inputMethodQuery (self, Qt.InputMethodQuery)
- bool isIndexHidden (self, QModelIndex)
- QAbstractItemDelegate itemDelegate (self)
- QAbstractItemDelegate itemDelegate (self, QModelIndex)
- QAbstractItemDelegate itemDelegateForColumn (self, int)
- QAbstractItemDelegate itemDelegateForRow (self, int)
- keyboardSearch (self, QString)
- keyPressEvent (self, QKeyEvent)
- QAbstractItemModel model (self)
- mouseDoubleClickEvent (self, QMouseEvent)
- mouseMoveEvent (self, QMouseEvent)
- mousePressEvent (self, QMouseEvent)
- mouseReleaseEvent (self, QMouseEvent)
- QModelIndex moveCursor (self, CursorAction, Qt.KeyboardModifiers)
- openPersistentEditor (self, QModelIndex)
- reset (self)
- resizeEvent (self, QResizeEvent)
- QModelIndex rootIndex (self)
- rowsAboutToBeRemoved (self, QModelIndex, int, int)
- rowsInserted (self, QModelIndex, int, int)
- scheduleDelayedItemsLayout (self)
- scrollDirtyRegion (self, int, int)
- scrollTo (self, QModelIndex, ScrollHint hint = QAbstractItemView.EnsureVisible)
- scrollToBottom (self)
- scrollToTop (self)
- selectAll (self)
- list-of-QModelIndex selectedIndexes (self)
- SelectionBehavior selectionBehavior (self)
- selectionChanged (self, QItemSelection, QItemSelection)
- QItemSelectionModel.SelectionFlags selectionCommand (self, QModelIndex, QEvent event = None)
- SelectionMode selectionMode (self)
- QItemSelectionModel selectionModel (self)
- setAlternatingRowColors (self, bool)
- setAutoScroll (self, bool)
- setAutoScrollMargin (self, int)
- setCurrentIndex (self, QModelIndex)
- setDefaultDropAction (self, Qt.DropAction)
- setDirtyRegion (self, QRegion)
- setDragDropMode (self, DragDropMode)
- setDragDropOverwriteMode (self, bool)
- setDragEnabled (self, bool)
- setDropIndicatorShown (self, bool)
- setEditTriggers (self, EditTriggers)
- setHorizontalScrollMode (self, ScrollMode)
- setHorizontalStepsPerItem (self, int)
- setIconSize (self, QSize)
- setIndexWidget (self, QModelIndex, QWidget)
- setItemDelegate (self, QAbstractItemDelegate)
- setItemDelegateForColumn (self, int, QAbstractItemDelegate)
- setItemDelegateForRow (self, int, QAbstractItemDelegate)
- setModel (self, QAbstractItemModel)
- setRootIndex (self, QModelIndex)
- setSelection (self, QRect, QItemSelectionModel.SelectionFlags)
- setSelectionBehavior (self, SelectionBehavior)
- setSelectionMode (self, SelectionMode)
- setSelectionModel (self, QItemSelectionModel)
- setState (self, State)
- setTabKeyNavigation (self, bool)
- setTextElideMode (self, Qt.TextElideMode)
- setVerticalScrollMode (self, ScrollMode)
- setVerticalStepsPerItem (self, int)
- bool showDropIndicator (self)
- int sizeHintForColumn (self, int)
- QSize sizeHintForIndex (self, QModelIndex)
- int sizeHintForRow (self, int)
- startDrag (self, Qt.DropActions)
- State state (self)
- bool tabKeyNavigation (self)
- Qt.TextElideMode textElideMode (self)
- timerEvent (self, QTimerEvent)
- update (self)
- update (self, QModelIndex)
- updateEditorData (self)
- updateEditorGeometries (self)
- updateGeometries (self)
- int verticalOffset (self)
- verticalScrollbarAction (self, int)
- verticalScrollbarValueChanged (self, int)
- ScrollMode verticalScrollMode (self)
- int verticalStepsPerItem (self)
- QStyleOptionViewItem viewOptions (self)
- bool viewportEvent (self, QEvent)
- QRect visualRect (self, QModelIndex)
- QRegion visualRegionForSelection (self, QItemSelection)

### Qt Signals

- void activated (const QModelIndex&)
- void clicked (const QModelIndex&)
- void doubleClicked (const QModelIndex&)
- void entered (const QModelIndex&)
- void pressed (const QModelIndex&)
- void viewportEntered ()

## 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 keyboard navigation implements this functionality:

Keys | Functionality
--- | ---
Arrow keys | Changes the current item and selects it.
Ctrl+Arrow keys | Changes the current item but does not select it.
Shift+Arrow keys | Changes the current item and selects it. The previously selected item(s) is not deselected.
Ctr+Space | Toggles selection of the current item.
Tab/Backtab | Changes the current item to the next/previous item.
Home/End | Selects the first/last item in the model.
Page up/Page down | Scrolls the rows shown up/down by the number of visible rows in the view.
Ctrl+A | Selects all items in the model.

Note that the above table assumes that the selection mode allows the operations. For instance, you cannot select items if the selection mode is QAbstractItemView.NoSelection.

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.

Note: If you inherit QAbstractItemView and intend to update the contents of the viewport, you should use viewport->update() instead of update() as all painting operations take place on the viewport.

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

## Type Documentation

### QAbstractItemView.CursorAction

This enum describes the different ways to navigate between items,

Constant | Value | Description
--- | --- | ---
`QAbstractItemView.MoveUp` | `0` | Move to the item above the current item.
`QAbstractItemView.MoveDown` | `1` | Move to the item below the current item.
`QAbstractItemView.MoveLeft` | `2` | Move to the item left of the current item.
`QAbstractItemView.MoveRight` | `3` | Move to the item right of the current item.
`QAbstractItemView.MoveHome` | `4` | Move to the top-left corner item.
`QAbstractItemView.MoveEnd` | `5` | Move to the bottom-right corner item.
`QAbstractItemView.MovePageUp` | `6` | Move one page up above the current item.
`QAbstractItemView.MovePageDown` | `7` | Move one page down below the current item.
`QAbstractItemView.MoveNext` | `8` | Move to the item after the current item.
`QAbstractItemView.MovePrevious` | `9` | Move to the item before the current item.

See also moveCursor().

### QAbstractItemView.DragDropMode

Describes the various drag and drop events the view can act upon. By default the view does not support dragging or dropping (`NoDragDrop`).

Constant | Value | Description
--- | --- | ---
`QAbstractItemView.NoDragDrop` | `0` | Does not support dragging or dropping.
`QAbstractItemView.DragOnly` | `1` | The view supports dragging of its own items
`QAbstractItemView.DropOnly` | `2` | The view accepts drops
`QAbstractItemView.DragDrop` | `3` | The view supports both dragging and dropping
`QAbstractItemView.InternalMove` | `4` | The view accepts move (not copy) operations only from itself.

Note that the model used needs to provide support for drag and drop operations.

This enum was introduced in Qt 4.2.

See also setDragDropMode() and Using Drag and Drop with Item Views.

### QAbstractItemView.DropIndicatorPosition

This enum indicates the position of the drop indicator in relation to the index at the current mouse position:

Constant | Value | Description
--- | --- | ---
`QAbstractItemView.OnItem` | `0` | The item will be dropped on the index.
`QAbstractItemView.AboveItem` | `1` | The item will be dropped above the index.
`QAbstractItemView.BelowItem` | `2` | The item will be dropped below the index.
`QAbstractItemView.OnViewport` | `3` | The item will be dropped onto a region of the viewport with no items. The way each view handles items dropped onto the viewport depends on the behavior of the underlying model in use.

### QAbstractItemView.EditTrigger

This enum describes actions which will initiate item editing.

Constant | Value | Description
--- | --- | ---
`QAbstractItemView.NoEditTriggers` | `0` | No editing possible.
`QAbstractItemView.CurrentChanged` | `1` | Editing start whenever current item changes.
`QAbstractItemView.DoubleClicked` | `2` | Editing starts when an item is double clicked.
`QAbstractItemView.SelectedClicked` | `4` | Editing starts when clicking on an already selected item.
`QAbstractItemView.EditKeyPressed` | `8` | Editing starts when the platform edit key has been pressed over an item.
`QAbstractItemView.AnyKeyPressed` | `16` | Editing starts when any key is pressed over an item.
`QAbstractItemView.AllEditTriggers` | `31` | Editing starts for all above actions.

The EditTriggers type is a typedef for QFlags<EditTrigger>. It stores an OR combination of EditTrigger values.

### QAbstractItemView.ScrollHint

Constant | Value | Description
--- | --- | ---
`QAbstractItemView.EnsureVisible` | `0` | Scroll to ensure that the item is visible.
`QAbstractItemView.PositionAtTop` | `1` | Scroll to position the item at the top of the viewport.
`QAbstractItemView.PositionAtBottom` | `2` | Scroll to position the item at the bottom of the viewport.
`QAbstractItemView.PositionAtCenter` | `3` | Scroll to position the item at the center of the viewport.

### QAbstractItemView.ScrollMode

Constant | Value | Description
--- | --- | ---
`QAbstractItemView.ScrollPerItem` | `0` | The view will scroll the contents one item at a time.
`QAbstractItemView.ScrollPerPixel` | `1` | The view will scroll the contents one pixel at a time.

This enum was introduced in Qt 4.2.

### QAbstractItemView.SelectionBehavior

Constant | Value | Description
--- | --- | ---
`QAbstractItemView.SelectItems` | `0` | Selecting single items.
`QAbstractItemView.SelectRows` | `1` | Selecting only rows.
`QAbstractItemView.SelectColumns` | `2` | Selecting only columns.

### QAbstractItemView.SelectionMode

This enum indicates how the view responds to user selections:

Constant | Value | Description
--- | --- | ---
`QAbstractItemView.SingleSelection` | `1` | When the user selects an item, any already-selected item becomes unselected, and the user cannot unselect the selected item by clicking on it.
`QAbstractItemView.ContiguousSelection` | `4` | When the user selects an item in the usual way, the selection is cleared and the new item selected. However, if the user presses the Shift key while clicking on an item, all items between the current item and the clicked item are selected or unselected, depending on the state of the clicked item.
`QAbstractItemView.ExtendedSelection` | `3` | When the user selects an item in the usual way, the selection is cleared and the new item selected. However, if the user presses the Ctrl key when clicking on an item, the clicked item gets toggled and all other items are left untouched. If the user presses the Shift key while clicking on an item, all items between the current item and the clicked item are selected or unselected, depending on the state of the clicked item. Multiple items can be selected by dragging the mouse over them.
`QAbstractItemView.MultiSelection` | `2` | When the user selects an item in the usual way, the selection status of that item is toggled and the other items are left alone. Multiple items can be toggled by dragging the mouse over them.
`QAbstractItemView.NoSelection` | `0` | Items cannot be selected.

The most commonly used modes are SingleSelection and ExtendedSelection.

### QAbstractItemView.State

Describes the different states the view can be in. This is usually only interesting when reimplementing your own view.

Constant | Value | Description
--- | --- | ---
`QAbstractItemView.NoState` | `0` | The is the default state.
`QAbstractItemView.DraggingState` | `1` | The user is dragging items.
`QAbstractItemView.DragSelectingState` | `2` | The user is selecting items.
`QAbstractItemView.EditingState` | `3` | The user is editing an item in a widget editor.
`QAbstractItemView.ExpandingState` | `4` | The user is opening a branch of items.
`QAbstractItemView.CollapsingState` | `5` | The user is closing a branch of items.
`QAbstractItemView.AnimatingState` | `6` | The item view is performing an animation.

## Method Documentation

### QAbstractItemView.__init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs an abstract item view with the given parent.

### bool QAbstractItemView.alternatingRowColors (self)

### int QAbstractItemView.autoScrollMargin (self)

### QAbstractItemView.clearSelection (self)

This method is also a Qt slot with the C++ signature `void clearSelection()`.

Deselects all selected items. The current index will not be changed.

See also setSelection() and selectAll().

### QAbstractItemView.closeEditor (self, QWidget, QAbstractItemDelegate.EndEditHint)

This method is also a Qt slot with the C++ signature `void closeEditor(QWidget *,QAbstractItemDelegate::EndEditHint)`.

Closes the given editor, and releases it. The hint is used to specify how the view should respond to the end of the editing operation. For example, the hint may indicate that the next item in the view should be opened for editing.

See also edit() and commitData().

### QAbstractItemView.closePersistentEditor (self, QModelIndex)

Closes the persistent editor for the item at the given index.

See also openPersistentEditor().

### QAbstractItemView.commitData (self, QWidget)

This method is also a Qt slot with the C++ signature `void commitData(QWidget *)`.

Commit the data in the editor to the model.

See also closeEditor().

### QAbstractItemView.currentChanged (self, QModelIndex, QModelIndex)

This method is also a Qt slot with the C++ signature `void currentChanged(const QModelIndex&,const QModelIndex&)`.

This slot is called when a new item becomes the current item. The previous current item is specified by the previous index, and the new item by the current index.

If you want to know about changes to items see the dataChanged() signal.

### QModelIndex QAbstractItemView.currentIndex (self)

Returns the model index of the current item.

See also setCurrentIndex().

### QAbstractItemView.dataChanged (self, QModelIndex, QModelIndex)

This method is also a Qt slot with the C++ signature `void dataChanged(const QModelIndex&,const QModelIndex&)`.

This slot is called when items are changed in the model. The changed items are those from topLeft to bottomRight inclusive. If just one item is changed topLeft == bottomRight.

### Qt.DropAction QAbstractItemView.defaultDropAction (self)

### QPoint QAbstractItemView.dirtyRegionOffset (self)

Returns the offset of the dirty regions in the view.

If you use scrollDirtyRegion() and implement a paintEvent() in a subclass of QAbstractItemView, you should translate the area given by the paint event with the offset returned from this function.

See also scrollDirtyRegion() and setDirtyRegion().

### QAbstractItemView.doItemsLayout (self)

This method is also a Qt slot with the C++ signature `void doItemsLayout()`.

### DragDropMode QAbstractItemView.dragDropMode (self)

### bool QAbstractItemView.dragDropOverwriteMode (self)

### bool QAbstractItemView.dragEnabled (self)

### QAbstractItemView.dragEnterEvent (self, QDragEnterEvent)

Reimplemented from QWidget.dragEnterEvent().

This function is called with the given event when a drag and drop operation enters the widget. If the drag is over a valid dropping place (e.g. over an item that accepts drops), the event is accepted; otherwise it is ignored.

See also dropEvent() and startDrag().

### QAbstractItemView.dragLeaveEvent (self, QDragLeaveEvent)

Reimplemented from QWidget.dragLeaveEvent().

This function is called when the item being dragged leaves the view. The event describes the state of the drag and drop operation.

### QAbstractItemView.dragMoveEvent (self, QDragMoveEvent)

Reimplemented from QWidget.dragMoveEvent().

This function is called continuously with the given event during a drag and drop operation over the widget. It can cause the view to scroll if, for example, the user drags a selection to view's right or bottom edge. In this case, the event will be accepted; otherwise it will be ignored.

See also dropEvent() and startDrag().

### QAbstractItemView.dropEvent (self, QDropEvent)

Reimplemented from QWidget.dropEvent().

This function is called with the given event when a drop event occurs over the widget. If the model accepts the even position the drop event is accepted; otherwise it is ignored.

See also startDrag().

### DropIndicatorPosition QAbstractItemView.dropIndicatorPosition (self)

Returns the position of the drop indicator in relation to the closest item.

This function was introduced in Qt 4.1.

### QAbstractItemView.edit (self, QModelIndex)

This method is also a Qt slot with the C++ signature `void edit(const QModelIndex&)`.

Starts editing the item corresponding to the given index if it is editable.

Note that this function does not change the current index. Since the current index defines the next and previous items to edit, users may find that keyboard navigation does not work as expected. To provide consistent navigation behavior, call setCurrentIndex() before this function with the same model index.

See also QModelIndex.flags().

### bool QAbstractItemView.edit (self, QModelIndex, EditTrigger, QEvent)

Starts editing the item at index, creating an editor if necessary, and returns true if the view's State is now EditingState; otherwise returns false.

The action that caused the editing process is described by trigger, and the associated event is specified by event.

Editing can be forced by specifying the trigger to be QAbstractItemView.AllEditTriggers.

See also closeEditor().

### QAbstractItemView.editorDestroyed (self, QObject)

This method is also a Qt slot with the C++ signature `void editorDestroyed(QObject *)`.

This function is called when the given editor has been destroyed.

See also closeEditor().

### EditTriggers QAbstractItemView.editTriggers (self)

### bool QAbstractItemView.event (self, QEvent)

Reimplemented from QObject.event().

### QAbstractItemView.executeDelayedItemsLayout (self)

Executes the scheduled layouts without waiting for the event processing to begin.

See also scheduleDelayedItemsLayout().

### QAbstractItemView.focusInEvent (self, QFocusEvent)

Reimplemented from QWidget.focusInEvent().

This function is called with the given event when the widget obtains the focus. By default, the event is ignored.

See also setFocus() and focusOutEvent().

### bool QAbstractItemView.focusNextPrevChild (self, bool)

Reimplemented from QWidget.focusNextPrevChild().

### QAbstractItemView.focusOutEvent (self, QFocusEvent)

Reimplemented from QWidget.focusOutEvent().

This function is called with the given event when the widget looses the focus. By default, the event is ignored.

See also clearFocus() and focusInEvent().

### bool QAbstractItemView.hasAutoScroll (self)

### int QAbstractItemView.horizontalOffset (self)

This method is abstract and should be reimplemented in any sub-class.

Returns the horizontal offset of the view.

In the base class this is a pure virtual function.

See also verticalOffset().

### QAbstractItemView.horizontalScrollbarAction (self, int)

This method is also a Qt slot with the C++ signature `void horizontalScrollbarAction(int)`.

### QAbstractItemView.horizontalScrollbarValueChanged (self, int)

This method is also a Qt slot with the C++ signature `void horizontalScrollbarValueChanged(int)`.

### ScrollMode QAbstractItemView.horizontalScrollMode (self)

### int QAbstractItemView.horizontalStepsPerItem (self)

### QSize QAbstractItemView.iconSize (self)

### QModelIndex QAbstractItemView.indexAt (self, QPoint)

This method is abstract and should be reimplemented in any sub-class.

Returns the model index of the item at the viewport coordinates point.

In the base class this is a pure virtual function.

See also visualRect().

### QWidget QAbstractItemView.indexWidget (self, QModelIndex)

Returns the widget for the item at the given index.

This function was introduced in Qt 4.1.

See also setIndexWidget().

### QAbstractItemView.inputMethodEvent (self, QInputMethodEvent)

Reimplemented from QWidget.inputMethodEvent().

### QVariant QAbstractItemView.inputMethodQuery (self, Qt.InputMethodQuery)

Reimplemented from QWidget.inputMethodQuery().

### bool QAbstractItemView.isIndexHidden (self, QModelIndex)

This method is abstract and should be reimplemented in any sub-class.

Returns true if the item referred to by the given index is hidden in the view, otherwise returns false.

Hiding is a view specific feature. For example in TableView a column can be marked as hidden or a row in the TreeView.

In the base class this is a pure virtual function.

### QAbstractItemDelegate QAbstractItemView.itemDelegate (self)

Returns the item delegate used by this view and model. This is either one set with setItemDelegate(), or the default one.

See also setItemDelegate().

### QAbstractItemDelegate QAbstractItemView.itemDelegate (self, QModelIndex)

Returns the item delegate used by this view and model for the given index.

### QAbstractItemDelegate QAbstractItemView.itemDelegateForColumn (self, int)

Returns the item delegate used by this view and model for the given column. You can call itemDelegate() to get a pointer to the current delegate for a given index.

This function was introduced in Qt 4.2.

See also setItemDelegateForColumn(), itemDelegateForRow(), and itemDelegate().

### QAbstractItemDelegate QAbstractItemView.itemDelegateForRow (self, int)

Returns the item delegate used by this view and model for the given row, or 0 if no delegate has been assigned. You can call itemDelegate() to get a pointer to the current delegate for a given index.

This function was introduced in Qt 4.2.

See also setItemDelegateForRow(), itemDelegateForColumn(), and setItemDelegate().

### QAbstractItemView.keyboardSearch (self, QString)

Moves to and selects the item best matching the string search. If no item is found nothing happens.

In the default implementation, the search is reset if search is empty, or the time interval since the last search has exceeded QApplication.keyboardInputInterval().

### QAbstractItemView.keyPressEvent (self, QKeyEvent)

Reimplemented from QWidget.keyPressEvent().

This function is called with the given event when a key event is sent to the widget. The default implementation handles basic cursor movement, e.g. Up, Down, Left, Right, Home, PageUp, and PageDown; the activated() signal is emitted if the current index is valid and the activation key is pressed (e.g. Enter or Return, depending on the platform). This function is where editing is initiated by key press, e.g. if F2 is pressed.

See also edit(), moveCursor(), keyboardSearch(), and tabKeyNavigation.

### QAbstractItemModel QAbstractItemView.model (self)

Returns the model that this view is presenting.

See also setModel().

### QAbstractItemView.mouseDoubleClickEvent (self, QMouseEvent)

Reimplemented from QWidget.mouseDoubleClickEvent().

This function is called with the given event when a mouse button is double clicked inside the widget. If the double-click is on a valid item it emits the doubleClicked() signal and calls edit() on the item.

### QAbstractItemView.mouseMoveEvent (self, QMouseEvent)

Reimplemented from QWidget.mouseMoveEvent().

This function is called with the given event when a mouse move event is sent to the widget. If a selection is in progress and new items are moved over the selection is extended; if a drag is in progress it is continued.

### QAbstractItemView.mousePressEvent (self, QMouseEvent)

Reimplemented from QWidget.mousePressEvent().

This function is called with the given event when a mouse button is pressed while the cursor is inside the widget. If a valid item is pressed on it is made into the current item. This function emits the pressed() signal.

### QAbstractItemView.mouseReleaseEvent (self, QMouseEvent)

Reimplemented from QWidget.mouseReleaseEvent().

This function is called with the given event when a mouse button is released, after a mouse press event on the widget. If a user presses the mouse inside your widget and then drags the mouse to another location before releasing the mouse button, your widget receives the release event. The function will emit the clicked() signal if an item was being pressed.

### QModelIndex QAbstractItemView.moveCursor (self, CursorAction, Qt.KeyboardModifiers)

This method is abstract and should be reimplemented in any sub-class.

Returns a QModelIndex object pointing to the next object in the view, based on the given cursorAction and keyboard modifiers specified by modifiers.

In the base class this is a pure virtual function.

### QAbstractItemView.openPersistentEditor (self, QModelIndex)

Opens a persistent editor on the item at the given index. If no editor exists, the delegate will create a new editor.

See also closePersistentEditor().

### QAbstractItemView.reset (self)

This method is also a Qt slot with the C++ signature `void reset()`.

Reset the internal state of the view.

Warning: This function will reset open editors, scroll bar positions, selections, etc. Existing changes will not be committed. If you would like to save your changes when resetting the view, you can reimplement this function, commit your changes, and then call the superclass' implementation.

### QAbstractItemView.resizeEvent (self, QResizeEvent)

Reimplemented from QWidget.resizeEvent().

This function is called with the given event when a resize event is sent to the widget.

See also QWidget.resizeEvent().

### QModelIndex QAbstractItemView.rootIndex (self)

Returns the model index of the model's root item. The root item is the parent item to the view's toplevel items. The root can be invalid.

See also setRootIndex().

### QAbstractItemView.rowsAboutToBeRemoved (self, QModelIndex, int, int)

This method is also a Qt slot with the C++ signature `void rowsAboutToBeRemoved(const QModelIndex&,int,int)`.

This slot is called when rows are about to be removed. The deleted rows are those under the given parent from start to end inclusive.

See also rowsInserted().

### QAbstractItemView.rowsInserted (self, QModelIndex, int, int)

This method is also a Qt slot with the C++ signature `void rowsInserted(const QModelIndex&,int,int)`.

This slot is called when rows are inserted. The new rows are those under the given parent from start to end inclusive. The base class implementation calls fetchMore() on the model to check for more data.

See also rowsAboutToBeRemoved().

### QAbstractItemView.scheduleDelayedItemsLayout (self)

Schedules a layout of the items in the view to be executed when the event processing starts.

Even if scheduleDelayedItemsLayout() is called multiple times before events are processed, the view will only do the layout once.

See also executeDelayedItemsLayout().

### QAbstractItemView.scrollDirtyRegion (self, int, int)

Prepares the view for scrolling by (dx,dy) pixels by moving the dirty regions in the opposite direction. You only need to call this function if you are implementing a scrolling viewport in your view subclass.

If you implement scrollContentsBy() in a subclass of QAbstractItemView, call this function before you call QWidget.scroll() on the viewport. Alternatively, just call update().

See also scrollContentsBy(), dirtyRegionOffset(), and setDirtyRegion().

### QAbstractItemView.scrollTo (self, QModelIndex, ScrollHint hint = QAbstractItemView.EnsureVisible)

This method is abstract and should be reimplemented in any sub-class.

Scrolls the view if necessary to ensure that the item at index is visible. The view will try to position the item according to the given hint.

In the base class this is a pure virtual function.

### QAbstractItemView.scrollToBottom (self)

This method is also a Qt slot with the C++ signature `void scrollToBottom()`.

Scrolls the view to the bottom.

This function was introduced in Qt 4.1.

See also scrollTo() and scrollToTop().

### QAbstractItemView.scrollToTop (self)

This method is also a Qt slot with the C++ signature `void scrollToTop()`.

Scrolls the view to the top.

This function was introduced in Qt 4.1.

See also scrollTo() and scrollToBottom().

### QAbstractItemView.selectAll (self)

This method is also a Qt slot with the C++ signature `void selectAll()`.

Selects all items in the view. This function will use the selection behavior set on the view when selecting.

See also setSelection(), selectedIndexes(), and clearSelection().

### list-of-QModelIndex QAbstractItemView.selectedIndexes (self)

This convenience function returns a list of all selected and non-hidden item indexes in the view. The list contains no duplicates, and is not sorted.

See also QItemSelectionModel.selectedIndexes().

### SelectionBehavior QAbstractItemView.selectionBehavior (self)

### QAbstractItemView.selectionChanged (self, QItemSelection, QItemSelection)

This method is also a Qt slot with the C++ signature `void selectionChanged(const QItemSelection&,const QItemSelection&)`.

This slot is called when the selection is changed. The previous selection (which may be empty), is specified by deselected, and the new selection by selected.

See also setSelection().

### QItemSelectionModel.SelectionFlags QAbstractItemView.selectionCommand (self, QModelIndex, QEvent event = None)

Returns the SelectionFlags to be used when updating a selection with to include the index specified. The event is a user input event, such as a mouse or keyboard event.

Reimplement this function to define your own selection behavior.

See also setSelection().

### SelectionMode QAbstractItemView.selectionMode (self)

### QItemSelectionModel QAbstractItemView.selectionModel (self)

Returns the current selection model.

See also setSelectionModel() and selectedIndexes().

### QAbstractItemView.setAlternatingRowColors (self, bool)

### QAbstractItemView.setAutoScroll (self, bool)

### QAbstractItemView.setAutoScrollMargin (self, int)

### QAbstractItemView.setCurrentIndex (self, QModelIndex)

This method is also a Qt slot with the C++ signature `void setCurrentIndex(const QModelIndex&)`.

Sets the current item to be the item at index.

Unless the current selection mode is NoSelection, the item is also be selected. Note that this function also updates the starting position for any new selections the user performs.

To set an item as the current item without selecting it, call

`selectionModel()->setCurrentIndex(index, QItemSelectionModel.NoUpdate);`

See also currentIndex(), currentChanged(), and selectionMode.

### QAbstractItemView.setDefaultDropAction (self, Qt.DropAction)

### QAbstractItemView.setDirtyRegion (self, QRegion)

Marks the given region as dirty and schedules it to be updated. You only need to call this function if you are implementing your own view subclass.

This function was introduced in Qt 4.1.

See also scrollDirtyRegion() and dirtyRegionOffset().

### QAbstractItemView.setDragDropMode (self, DragDropMode)

### QAbstractItemView.setDragDropOverwriteMode (self, bool)

### QAbstractItemView.setDragEnabled (self, bool)

### QAbstractItemView.setDropIndicatorShown (self, bool)

### QAbstractItemView.setEditTriggers (self, EditTriggers)

### QAbstractItemView.setHorizontalScrollMode (self, ScrollMode)

### QAbstractItemView.setHorizontalStepsPerItem (self, int)

### QAbstractItemView.setIconSize (self, QSize)

### QAbstractItemView.setIndexWidget (self, QModelIndex, QWidget)

The QWidget argument has it's ownership transferred to Qt.

Sets the given widget on the item at the given index, passing the ownership of the widget to the viewport.

If index is invalid (e.g., if you pass the root index), this function will do nothing.

The given widget's autoFillBackground property must be set to true, otherwise the widget's background will be transparent, showing both the model data and the item at the given index.

If index widget A is replaced with index widget B, index widget A will be deleted. For example, in the code snippet below, the QLineEdit object will be deleted.

     setIndexWidget(index, new QLineEdit);
     ...
     setIndexWidget(index, new QTextEdit);

This function should only be used to display static content within the visible area corresponding to an item of data. If you want to display custom dynamic content or implement a custom editor widget, subclass QItemDelegate instead.

This function was introduced in Qt 4.1.

See also indexWidget() and Delegate Classes.

### QAbstractItemView.setItemDelegate (self, QAbstractItemDelegate)

Sets the item delegate for this view and its model to delegate. This is useful if you want complete control over the editing and display of items.

Any existing delegate will be removed, but not deleted. QAbstractItemView does not take ownership of delegate.

Warning: You should not share the same instance of a delegate between views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the closeEditor() signal, and attempt to access, modify or close an editor that has already been closed.

See also itemDelegate().

### QAbstractItemView.setItemDelegateForColumn (self, int, QAbstractItemDelegate)

Sets the given item delegate used by this view and model for the given column. All items on column will be drawn and managed by delegate instead of using the default delegate (i.e., itemDelegate()).

Any existing column delegate for column will be removed, but not deleted. QAbstractItemView does not take ownership of delegate.

Note: If a delegate has been assigned to both a row and a column, the row delegate will take presedence and manage the intersecting cell index.

Warning: You should not share the same instance of a delegate between views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the closeEditor() signal, and attempt to access, modify or close an editor that has already been closed.

This function was introduced in Qt 4.2.

See also itemDelegateForColumn(), setItemDelegateForRow(), and itemDelegate().

### QAbstractItemView.setItemDelegateForRow (self, int, QAbstractItemDelegate)

Sets the given item delegate used by this view and model for the given row. All items on row will be drawn and managed by delegate instead of using the default delegate (i.e., itemDelegate()).

Any existing row delegate for row will be removed, but not deleted. QAbstractItemView does not take ownership of delegate.

Note: If a delegate has been assigned to both a row and a column, the row delegate (i.e., this delegate) will take presedence and manage the intersecting cell index.

Warning: You should not share the same instance of a delegate between views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the closeEditor() signal, and attempt to access, modify or close an editor that has already been closed.

This function was introduced in Qt 4.2.

See also itemDelegateForRow(), setItemDelegateForColumn(), and itemDelegate().

### QAbstractItemView.setModel (self, QAbstractItemModel)

Sets the model for the view to present.

This function will create and set a new selection model, replacing any model that was previously set with setSelectionModel(). However, the old selection model will not be deleted as it may be shared between several views. We recommend that you delete the old selection model if it is no longer required. This is done with the following code:

     QItemSelectionModel *m = view->selectionModel();
     view->setModel(new model);
     delete m;

If both the old model and the old selection model do not have parents, or if their parents are long-lived objects, it may be preferable to call their deleteLater() functions to explicitly delete them.

The view does not take ownership of the model unless it is the model's parent object because the view may be shared between many different views.

See also model(), selectionModel(), and setSelectionModel().

### QAbstractItemView.setRootIndex (self, QModelIndex)

This method is also a Qt slot with the C++ signature `void setRootIndex(const QModelIndex&)`.

Sets the root item to the item at the given index.

See also rootIndex().

### QAbstractItemView.setSelection (self, QRect, QItemSelectionModel.SelectionFlags)

This method is abstract and should be reimplemented in any sub-class.

Applies the selection flags to the items in or touched by the rectangle, rect.

When implementing your own itemview setSelection should call selectionModel()->select(selection, flags) where selection is either an empty QModelIndex or a QItemSelection that contains all items that are contained in rect.

See also selectionCommand() and selectedIndexes().

### QAbstractItemView.setSelectionBehavior (self, SelectionBehavior)

### QAbstractItemView.setSelectionMode (self, SelectionMode)

### QAbstractItemView.setSelectionModel (self, QItemSelectionModel)

Sets the current selection model to the given selectionModel.

Note that, if you call setModel() after this function, the given selectionModel will be replaced by one created by the view.

Note: It is up to the application to delete the old selection model if it is no longer needed; i.e., if it is not being used by other views. This will happen automatically when its parent object is deleted. However, if it does not have a parent, or if the parent is a long-lived object, it may be preferable to call its deleteLater() function to explicitly delete it.

See also selectionModel(), setModel(), and clearSelection().

### QAbstractItemView.setState (self, State)

Sets the item view's state to the given state.

See also state().

### QAbstractItemView.setTabKeyNavigation (self, bool)

### QAbstractItemView.setTextElideMode (self, Qt.TextElideMode)

### QAbstractItemView.setVerticalScrollMode (self, ScrollMode)

### QAbstractItemView.setVerticalStepsPerItem (self, int)

### bool QAbstractItemView.showDropIndicator (self)

### int QAbstractItemView.sizeHintForColumn (self, int)

Returns the width size hint for the specified column or -1 if there is no model.

This function is used in views with a horizontal header to find the size hint for a header section based on the contents of the given column.

See also sizeHintForRow().

### QSize QAbstractItemView.sizeHintForIndex (self, QModelIndex)

Returns the size hint for the item with the specified index or an invalid size for invalid indexes.

See also sizeHintForRow() and sizeHintForColumn().

### int QAbstractItemView.sizeHintForRow (self, int)

Returns the height size hint for the specified row or -1 if there is no model.

The returned height is calculated using the size hints of the given row's items, i.e. the returned value is the maximum height among the items. Note that to control the height of a row, you must reimplement the QAbstractItemDelegate.sizeHint() function.

This function is used in views with a vertical header to find the size hint for a header section based on the contents of the given row.

See also sizeHintForColumn().

### QAbstractItemView.startDrag (self, Qt.DropActions)

Starts a drag by calling drag->exec() using the given supportedActions.

### State QAbstractItemView.state (self)

Returns the item view's state.

See also setState().

### bool QAbstractItemView.tabKeyNavigation (self)

### Qt.TextElideMode QAbstractItemView.textElideMode (self)

### QAbstractItemView.timerEvent (self, QTimerEvent)

Reimplemented from QObject.timerEvent().

This function is called with the given event when a timer event is sent to the widget.

See also QObject.timerEvent().

### QAbstractItemView.update (self)

This method is also a Qt slot with the C++ signature `void update()`.

Updates the area occupied by the given index.

This function was introduced in Qt 4.3.

### QAbstractItemView.update (self, QModelIndex)

This method is also a Qt slot with the C++ signature `void update(const QModelIndex&)`.

### QAbstractItemView.updateEditorData (self)

This method is also a Qt slot with the C++ signature `void updateEditorData()`.

### QAbstractItemView.updateEditorGeometries (self)

This method is also a Qt slot with the C++ signature `void updateEditorGeometries()`.

### QAbstractItemView.updateGeometries (self)

This method is also a Qt slot with the C++ signature `void updateGeometries()`.

Updates the geometry of the child widgets of the view.

This function was introduced in Qt 4.4.

### int QAbstractItemView.verticalOffset (self)

This method is abstract and should be reimplemented in any sub-class.

Returns the vertical offset of the view.

In the base class this is a pure virtual function.

See also horizontalOffset().

### QAbstractItemView.verticalScrollbarAction (self, int)

This method is also a Qt slot with the C++ signature `void verticalScrollbarAction(int)`.

### QAbstractItemView.verticalScrollbarValueChanged (self, int)

This method is also a Qt slot with the C++ signature `void verticalScrollbarValueChanged(int)`.

### ScrollMode QAbstractItemView.verticalScrollMode (self)

### int QAbstractItemView.verticalStepsPerItem (self)

### QStyleOptionViewItem QAbstractItemView.viewOptions (self)

Returns a QStyleOptionViewItem structure populated with the view's palette, font, state, alignments etc.

### bool QAbstractItemView.viewportEvent (self, QEvent)

Reimplemented from QAbstractScrollArea.viewportEvent().

This function is used to handle tool tips, and What's This? mode, if the given event is a QEvent.ToolTip,or a QEvent.WhatsThis. It passes all other events on to its base class viewportEvent() handler.

### QRect QAbstractItemView.visualRect (self, QModelIndex)

This method is abstract and should be reimplemented in any sub-class.

Returns the rectangle on the viewport occupied by the item at index.

If your item is displayed in several areas then visualRect should return the primary area that contains index and not the complete area that index might encompasses, touch or cause drawing.

In the base class this is a pure virtual function.

See also indexAt() and visualRegionForSelection().

### QRegion QAbstractItemView.visualRegionForSelection (self, QItemSelection)

This method is abstract and should be reimplemented in any sub-class.

Returns the region from the viewport of the items in the given selection.

In the base class this is a pure virtual function.

See also visualRect() and selectedIndexes().

## Qt Signal Documentation

### void activated (const QModelIndex&)

This is the default overload of this signal.

This signal is emitted when the item specified by index is activated by the user. How to activate items depends on the platform; e.g., by single- or double-clicking the item, or by pressing the Return or Enter key when the item is current.

See also clicked(), doubleClicked(), entered(), and pressed().

### void clicked (const QModelIndex&)

This is the default overload of this signal.

This signal is emitted when a mouse button is clicked. The item the mouse was clicked on is specified by index. The signal is only emitted when the index is valid.

See also activated(), doubleClicked(), entered(), and pressed().

### void doubleClicked (const QModelIndex&)

This is the default overload of this signal.

This signal is emitted when a mouse button is double-clicked. The item the mouse was double-clicked on is specified by index. The signal is only emitted when the index is valid.

See also clicked() and activated().

### void entered (const QModelIndex&)

This is the default overload of this signal.

This signal is emitted when the mouse cursor enters the item specified by index. Mouse tracking needs to be enabled for this feature to work.

See also viewportEntered(), activated(), clicked(), doubleClicked(), and pressed().

### void pressed (const QModelIndex&)

This is the default overload of this signal.

This signal is emitted when a mouse button is pressed. The item the mouse was pressed on is specified by index. The signal is only emitted when the index is valid.

Use the QApplication.mouseButtons() function to get the state of the mouse buttons.

See also activated(), clicked(), doubleClicked(), and entered().

### void viewportEntered ()

This is the default overload of this signal.

This signal is emitted when the mouse cursor enters the viewport. Mouse tracking needs to be enabled for this feature to work.

See also entered().