Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
The QAbstractItemDelegate class is used to display and edit data items from a model. More...
#include <QAbstractItemDelegate>
Inherits QObject.
Inherited by QItemDelegate.
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.
This enum describes how an editor was invoked to edit an item.
QAbstractItemDelegate::NeverEdit | The item cannot be edited. |
QAbstractItemDelegate::CurrentChanged | The focus was moved to the item. |
QAbstractItemDelegate::DoubleClicked | The item was double-clicked. |
QAbstractItemDelegate::SelectedClicked | The item was select-clicked (e.g. Shift+Click, or Ctrl+Click). |
QAbstractItemDelegate::EditKeyPressed | An edit key was pressed (often F2). |
QAbstractItemDelegate::AnyKeyPressed | A key was pressed when the item had the focus. |
QAbstractItemDelegate::AlwaysEdit | The editor is always present. |
The BeginEditActions typedef can store a combination of BeginEditAction values.
This enum describes what must be done to create an editor for an item.
QAbstractItemDelegate::Widget | The editor() is a widget. |
QAbstractItemDelegate::Events | There is no editor() widget; used if event() is reimplemented. |
QAbstractItemDelegate::Accepted | The user accepted their edit. (Usually signified by pressing Enter.) |
QAbstractItemDelegate::Cancelled | The user rejected their edit. (Usually signified by pressing Esc.) |
Creates a new abstract item delegate with the given parent.
Destroys the abstract item delegate.
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().
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().
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.
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.
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().
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().
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().
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().
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().
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 |