Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QAbstractItemDelegate Class Reference

The QAbstractItemDelegate class is used to display and edit data items from a model. More...

    #include <QAbstractItemDelegate>

Inherits QObject.

Inherited by QItemDelegate.

- List of all members, including inherited members

### Writable Properties

- 1 writable property inherited from QObject

### Public Functions

- QAbstractItemDelegate ( QObject * parent = 0 )
- virtual ~QAbstractItemDelegate ()
- virtual QWidget * editor ( QWidget * parent, const QStyleOptionViewItem & option, const QAbstractItemModel * model, const QModelIndex & index )
- virtual bool editorEvent ( QEvent * e, QAbstractItemModel * model, const QModelIndex & index )
- virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QAbstractItemModel * model, const QModelIndex & index ) const = 0
- virtual void releaseEditor ( QWidget * editor )
- virtual void setEditorData ( QWidget * editor, const QAbstractItemModel * model, const QModelIndex & index ) const
- virtual void setModelData ( QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const
- virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QAbstractItemModel * model, const QModelIndex & index ) const = 0
- virtual void updateEditorGeometry ( QWidget * editor, const QStyleOptionViewItem & option, const QAbstractItemModel * model, const QModelIndex & index ) const

- 24 public functions inherited from QObject

### Public Slots

- 1 public slot inherited from QObject

### Signals

- void commitData ( QWidget * editor )
- void doneEditing ( QWidget * editor )

- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QObject

### Protected Functions

- QString ellipsisText ( const QFontMetrics & fontMetrics, int width, int align, const QString & org ) const

- 9 protected functions inherited from QObject

## Detailed Description

The QAbstractItemDelegate class is used to display and edit data items from a model.

A QAbstractItemDelegate provides the interface and common functionality for delegates in the model/view architecture. Delegates display individual items in views, and handle the editing of model data.

To render an item in a custom way, you must implement paint() and sizeHint(). The QItemDelegate class provides default implementations for these functions; if you do not need custom rendering, subclass that class instead.

To provide custom editing, there are two approaches that can be used. The first approach is to create an editor widget and display it directly on top of the item. To do this you must reimplement editor() to provide an editor widget, setEditorData() to populate the editor with the data from the model setModelData() so that the delegate can update the model with data from the editor, and releaseEditor() to destroy your editor when it is no longer needed. The second approach is to handle user events directly. To do this you could reimplement editorEvent().

See also Model/View Programming and QItemDelegate.

## Member Function Documentation

### QAbstractItemDelegate::QAbstractItemDelegate ( QObject * parent = 0 )

Creates a new abstract item delegate with the given parent.

### QAbstractItemDelegate::~QAbstractItemDelegate () `[virtual]`

Destroys the abstract item delegate.

### void QAbstractItemDelegate::commitData ( QWidget * editor ) `[signal]`

This signal is emitted when... ### FIXME ###

### void QAbstractItemDelegate::doneEditing ( QWidget * editor ) `[signal]`

This signal is emitted when the user has finished editing an item. The arguments are the editor that was used.

### QWidget * QAbstractItemDelegate::editor ( QWidget * parent, const QStyleOptionViewItem & option, const QAbstractItemModel * model, const QModelIndex & index ) `[virtual]`

Returns the editor to be used for editing the data item at the given index in the model. The editor's parent widget is specified by parent, and the item options by option. Ownership is kept by the delegate. Subsequent calls to this function with the same arguments are not guaranteed to return the same editor object.

Note: When the editor is no longer in use, call releaseEditor().

The base implementation returns 0. If you want custom editing you will need to reimplement this function.

See also setModelData(), setEditorData(), and releaseEditor().

### bool QAbstractItemDelegate::editorEvent ( QEvent * e, QAbstractItemModel * model, const QModelIndex & index ) `[virtual]`

Whenever an event occurs, this function is called with the e and the model index in the model.

The base implementation returns false (indicating that it has not handled the event).

### QString QAbstractItemDelegate::ellipsisText ( const QFontMetrics & fontMetrics, int width, int align, const QString & org ) const `[protected]`

Creates a string with an ellipses ("..."), for example, "Trollte..." or "...olltech" depending on the alignment. This is used to display items that are too wide to fit. The font metrics to be used are given by fontMetrics, the available width by width, the alignment by align, and the string by org.

### void QAbstractItemDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QAbstractItemModel * model, const QModelIndex & index ) const `[pure virtual]`

This pure abstract function must be reimplemented if you want to provide custom rendering. Use the painter and style option to render the item specified by the model and the item index.

If you reimplement this you must also reimplement sizeHint().

### void QAbstractItemDelegate::releaseEditor ( QWidget * editor ) `[virtual]`

Notifies the delegate that the given editor is no longer in use. Typically the delegate should destroy the editor at this point.

The base implementation does nothing. If you want custom editing you will probably need to reimplement this function.

See also editor(), setEditorData(), and setModelData().

### void QAbstractItemDelegate::setEditorData ( QWidget * editor, const QAbstractItemModel * model, const QModelIndex & index ) const `[virtual]`

Sets the contents of the given editor to the data for the item at the given index, in the model model.

The base implementation does nothing. If you want custom editing you will need to reimplement this function.

See also editor(), setModelData(), and releaseEditor().

### void QAbstractItemDelegate::setModelData ( QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const `[virtual]`

Sets the data for the item at the given index in the model to the contents of the given editor.

The base implementation does nothing. If you want custom editing you will need to reimplement this function.

See also editor(), setEditorData(), and releaseEditor().

### QSize QAbstractItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QAbstractItemModel * model, const QModelIndex & index ) const `[pure virtual]`

This pure abstract function must be reimplemented if you want to provide custom rendering. The options are specified by option, the model by model, and the model item by index.

If you reimplement this you must also reimplement paint().

### void QAbstractItemDelegate::updateEditorGeometry ( QWidget * editor, const QStyleOptionViewItem & option, const QAbstractItemModel * model, const QModelIndex & index ) const `[virtual]`

Updates the geometry of the editor for the item in the model with the given index, according to the rectangle specified in the option. If the item has an internal layout, the editor will be laid out accordingly.

The base implementation does nothing. If you want custom editing you must reimplement this function.

See also editor() and releaseEditor().