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.

Public Types

Writable Properties

Public Functions

Public Slots

Signals

Static Public Members

Protected Functions


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() and editorType() 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 event().

See also Model/View Programming and QItemDelegate.


Member Type Documentation

enum QAbstractItemDelegate::BeginEditAction
typedef QAbstractItemDelegate::BeginEditActions

This enum describes how an editor was invoked to edit an item.

QAbstractItemDelegate::NeverEditThe item cannot be edited.
QAbstractItemDelegate::CurrentChangedThe focus was moved to the item.
QAbstractItemDelegate::DoubleClickedThe item was double-clicked.
QAbstractItemDelegate::SelectedClickedThe item was select-clicked (e.g. Shift+Click, or Ctrl+Click).
QAbstractItemDelegate::EditKeyPressedAn edit key was pressed (often F2).
QAbstractItemDelegate::AnyKeyPressedA key was pressed when the item had the focus.
QAbstractItemDelegate::AlwaysEditThe editor is always present.

The BeginEditActions typedef can store a combination of BeginEditAction values.

enum QAbstractItemDelegate::EditorType

This enum describes what must be done to create an editor for an item.

QAbstractItemDelegate::WidgetThe editor() is a widget.
QAbstractItemDelegate::EventsThere is no editor() widget; used if event() is reimplemented.

enum QAbstractItemDelegate::EndEditAction

QAbstractItemDelegate::AcceptedThe user accepted their edit. (Usually signified by pressing Enter.)
QAbstractItemDelegate::CancelledThe user rejected their edit. (Usually signified by pressing Esc.)

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.

QWidget * QAbstractItemDelegate::editor ( BeginEditAction action, 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 action that caused the edit is specified by action; see BeginEditAction. 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 editorType(), setModelData(), setEditorData(), and releaseEditor().

EditorType QAbstractItemDelegate::editorType ( const QAbstractItemModel * model, const QModelIndex & index ) const   [virtual]

Returns the EditorType for the item at the given index in the model.

If you provide an editor(), you will want to reimplement this function to return the EditorType appropriate to your editor().

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.

bool QAbstractItemDelegate::event ( 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). If you reimplement this you should reimplement editorType() to return Events.

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 ( EndEditAction action, QWidget * editor, QAbstractItemModel * model, const QModelIndex & index )   [virtual]

Notifies the delegate that the given editor is no longer in use for the item at the given index in the model. The way the edit was completed is specified by action; see EndEditAction. 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 editorType(), 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 editorType(), 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 editorType(), editor(), setEditorData(), and releaseEditor().

QSize QAbstractItemDelegate::sizeHint ( const QFontMetrics & fontMetrics, 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 font metrics are specified by fontMetrics, the options 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 editorType(), editor(), and releaseEditor().


Copyright © 2004 Trolltech. Trademarks
Qt 4.0.0-tp1