1
<?xml version="1.0" encoding="iso-8859-1"?>
3
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/gui/itemviews/qitemdelegate.cpp -->
7
<title>Qt 4.0: QItemDelegate Class Reference</title>
8
<style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
9
a:link { color: #004faf; text-decoration: none }
10
a:visited { color: #672967; text-decoration: none }
11
td.postheader { font-family: sans-serif }
12
tr.address { font-family: sans-serif }
13
body { background: #ffffff; color: black; }</style>
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
19
<td width="1"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> · <a href="annotated.html"><font color="#004faf">Annotated</font></a> · <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> · <a href="functions.html"><font color="#004faf">Functions</font></a></td>
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QItemDelegate Class Reference</h1>
21
<p>The QItemDelegate class provides display and editing facilities for data items from a model. <a href="#details">More...</a></p>
22
<pre>#include <QItemDelegate></pre><p>Part of the <a href="qtgui.html">QtGui</a> module.</p>
23
<p>Inherits <a href="qabstractitemdelegate.html">QAbstractItemDelegate</a>.</p>
24
<p>Inherited by <a href="qsqlrelationaldelegate.html">QSqlRelationalDelegate</a>.</p>
26
<li><a href="qitemdelegate-members.html">List of all members, including inherited members</a></li>
28
<a name="public-functions"></a>
29
<h3>Public Functions</h3>
31
<li><div class="fn"/><b><a href="qitemdelegate.html#QItemDelegate">QItemDelegate</a></b> ( QObject * <i>parent</i> = 0 )</li>
32
<li><div class="fn"/><b><a href="qitemdelegate.html#dtor.QItemDelegate">~QItemDelegate</a></b> ()</li>
33
<li><div class="fn"/>virtual QWidget * <b><a href="qitemdelegate.html#createEditor">createEditor</a></b> ( QWidget * <i>parent</i>, const QStyleOptionViewItem & <i>option</i>, const QModelIndex & <i>index</i> ) const</li>
34
<li><div class="fn"/>QItemEditorFactory * <b><a href="qitemdelegate.html#itemEditorFactory">itemEditorFactory</a></b> () const</li>
35
<li><div class="fn"/>virtual void <b><a href="qitemdelegate.html#paint">paint</a></b> ( QPainter * <i>painter</i>, const QStyleOptionViewItem & <i>option</i>, const QModelIndex & <i>index</i> ) const</li>
36
<li><div class="fn"/>virtual void <b><a href="qitemdelegate.html#setEditorData">setEditorData</a></b> ( QWidget * <i>editor</i>, const QModelIndex & <i>index</i> ) const</li>
37
<li><div class="fn"/>void <b><a href="qitemdelegate.html#setItemEditorFactory">setItemEditorFactory</a></b> ( QItemEditorFactory * <i>factory</i> )</li>
38
<li><div class="fn"/>virtual void <b><a href="qitemdelegate.html#setModelData">setModelData</a></b> ( QWidget * <i>editor</i>, QAbstractItemModel * <i>model</i>, const QModelIndex & <i>index</i> ) const</li>
39
<li><div class="fn"/>virtual QSize <b><a href="qitemdelegate.html#sizeHint">sizeHint</a></b> ( const QStyleOptionViewItem & <i>option</i>, const QModelIndex & <i>index</i> ) const</li>
40
<li><div class="fn"/>virtual void <b><a href="qitemdelegate.html#updateEditorGeometry">updateEditorGeometry</a></b> ( QWidget * <i>editor</i>, const QStyleOptionViewItem & <i>option</i>, const QModelIndex & <i>index</i> ) const</li>
43
<li><div class="fn"/>7 public functions inherited from <a href="qabstractitemdelegate.html#public-functions">QAbstractItemDelegate</a></li>
44
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
46
<a name="protected-functions"></a>
47
<h3>Protected Functions</h3>
49
<li><div class="fn"/>virtual void <b><a href="qitemdelegate.html#drawCheck">drawCheck</a></b> ( QPainter * <i>painter</i>, const QStyleOptionViewItem & <i>option</i>, const QRect & <i>rect</i>, Qt::CheckState <i>state</i> ) const</li>
50
<li><div class="fn"/>virtual void <b><a href="qitemdelegate.html#drawDecoration">drawDecoration</a></b> ( QPainter * <i>painter</i>, const QStyleOptionViewItem & <i>option</i>, const QRect & <i>rect</i>, const QPixmap & <i>pixmap</i> ) const</li>
51
<li><div class="fn"/>virtual void <b><a href="qitemdelegate.html#drawDisplay">drawDisplay</a></b> ( QPainter * <i>painter</i>, const QStyleOptionViewItem & <i>option</i>, const QRect & <i>rect</i>, const QString & <i>text</i> ) const</li>
52
<li><div class="fn"/>virtual void <b><a href="qitemdelegate.html#drawFocus">drawFocus</a></b> ( QPainter * <i>painter</i>, const QStyleOptionViewItem & <i>option</i>, const QRect & <i>rect</i> ) const</li>
55
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
57
<h3>Additional Inherited Members</h3>
59
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
60
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
61
<li><div class="fn"/>2 signals inherited from <a href="qabstractitemdelegate.html#signals">QAbstractItemDelegate</a></li>
62
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
63
<li><div class="fn"/>1 static public member inherited from <a href="qabstractitemdelegate.html#static-public-members">QAbstractItemDelegate</a></li>
64
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
66
<a name="details"></a>
68
<h2>Detailed Description</h2>
69
<p>The QItemDelegate class provides display and editing facilities for data items from a model.</p>
70
<p>A QItemDelegate can be used to provide an editor for an item view class that is subclassed from <a href="qabstractitemview.html">QAbstractItemView</a>. Using a delegate for this purpose allows the editing mechanism to be customized and developed independently from the model and view.</p>
71
<p>The QItemDelegate class is one of the <a href="model-view.html">Model/View Classes</a> and is part of Qt's <a href="model-view-programming.html">model/view framework</a>.</p>
72
<p>Delegates can be used to manipulate data in two complementary ways: by processing events in the normal manner, or by implementing a custom editor widget. The item delegate takes the approach of providing a widget for editing purposes that can be supplied to QAbstractItemView::setDelegate() or the equivalent function in subclasses of <a href="qabstractitemview.html">QAbstractItemView</a>.</p>
73
<p>This class demonstrates how to implement the functions for painting the delegate, and editing data from the model. The <a href="qitemdelegate.html#paint">paint</a>() and <a href="qitemdelegate.html#sizeHint">sizeHint</a>() virtual functions defined in <a href="qabstractitemdelegate.html">QAbstractItemDelegate</a> are implemented to ensure that the delegate is presented correctly. Only the standard editing functions for widget-based delegates are reimplemented here: editor() returns the widget used to change data from the model; <a href="qitemdelegate.html#setEditorData">setEditorData</a>() provides the widget with data to manipulate; <a href="qitemdelegate.html#updateEditorGeometry">updateEditorGeometry</a>() ensures that the editor is displayed correctly with respect to the item view; <a href="qitemdelegate.html#setModelData">setModelData</a>() returns the updated data to the model; releaseEditor() indicates that the user has completed editing the data, and that the editor widget can be destroyed.</p>
74
<p>See also <a href="model-view-programming.html">Model/View Programming</a> and <a href="qabstractitemdelegate.html">QAbstractItemDelegate</a>.</p>
76
<h2>Member Function Documentation</h2>
77
<h3 class="fn"><a name="QItemDelegate"></a>QItemDelegate::QItemDelegate ( <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
78
<p>Constructs an item delegate with the given <i>parent</i>.</p>
79
<h3 class="fn"><a name="dtor.QItemDelegate"></a>QItemDelegate::~QItemDelegate ()</h3>
80
<p>Destroys the item delegate.</p>
81
<h3 class="fn"><a name="createEditor"></a><a href="qwidget.html">QWidget</a> * QItemDelegate::createEditor ( <a href="qwidget.html">QWidget</a> * <i>parent</i>, const <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a> & <i>option</i>, const <a href="qmodelindex.html">QModelIndex</a> & <i>index</i> ) const <tt> [virtual]</tt></h3>
82
<p>Returns the widget used to edit the item specified by <i>index</i> for editing. The <i>parent</i> widget and style <i>option</i> are used to control how the editor widget appears.</p>
83
<p>Reimplemented from <a href="qabstractitemdelegate.html#createEditor">QAbstractItemDelegate</a>.</p>
84
<p>See also <a href="qabstractitemdelegate.html#createEditor">QAbstractItemDelegate::createEditor</a>().</p>
85
<h3 class="fn"><a name="drawCheck"></a>void QItemDelegate::drawCheck ( <a href="qpainter.html">QPainter</a> * <i>painter</i>, const <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a> & <i>option</i>, const <a href="qrect.html">QRect</a> & <i>rect</i>, <a href="qt.html#CheckState-enum">Qt::CheckState</a> <i>state</i> ) const <tt> [virtual protected]</tt></h3>
86
<p>Renders a check indicator within the rectangle specified by <i>rect</i>, using the given <i>painter</i> and style <i>option</i>, using the given <i>state</i>.</p>
87
<h3 class="fn"><a name="drawDecoration"></a>void QItemDelegate::drawDecoration ( <a href="qpainter.html">QPainter</a> * <i>painter</i>, const <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a> & <i>option</i>, const <a href="qrect.html">QRect</a> & <i>rect</i>, const <a href="qpixmap.html">QPixmap</a> & <i>pixmap</i> ) const <tt> [virtual protected]</tt></h3>
88
<p>Renders the decoration <i>pixmap</i> within the rectangle specified by <i>rect</i> using the given <i>painter</i> and style <i>option</i>.</p>
89
<h3 class="fn"><a name="drawDisplay"></a>void QItemDelegate::drawDisplay ( <a href="qpainter.html">QPainter</a> * <i>painter</i>, const <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a> & <i>option</i>, const <a href="qrect.html">QRect</a> & <i>rect</i>, const <a href="qstring.html">QString</a> & <i>text</i> ) const <tt> [virtual protected]</tt></h3>
90
<p>Renders the item view <i>text</i> within the rectangle specified by <i>rect</i> using the given <i>painter</i> and style <i>option</i>.</p>
91
<h3 class="fn"><a name="drawFocus"></a>void QItemDelegate::drawFocus ( <a href="qpainter.html">QPainter</a> * <i>painter</i>, const <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a> & <i>option</i>, const <a href="qrect.html">QRect</a> & <i>rect</i> ) const <tt> [virtual protected]</tt></h3>
92
<p>Renders the region within the rectangle specified by <i>rect</i>, indicating that it has the focus, using the given <i>painter</i> and style <i>option</i>.</p>
93
<h3 class="fn"><a name="itemEditorFactory"></a><a href="qitemeditorfactory.html">QItemEditorFactory</a> * QItemDelegate::itemEditorFactory () const</h3>
94
<p>Returns the editor factory used by the item delegate. If no editor factory is set, the function will return null.</p>
95
<h3 class="fn"><a name="paint"></a>void QItemDelegate::paint ( <a href="qpainter.html">QPainter</a> * <i>painter</i>, const <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a> & <i>option</i>, const <a href="qmodelindex.html">QModelIndex</a> & <i>index</i> ) const <tt> [virtual]</tt></h3>
96
<p>Renders the delegate using the given <i>painter</i> and style <i>option</i> for the item specified by <i>index</i>.</p>
97
<p>Reimplemented from <a href="qabstractitemdelegate.html#paint">QAbstractItemDelegate</a>.</p>
98
<h3 class="fn"><a name="setEditorData"></a>void QItemDelegate::setEditorData ( <a href="qwidget.html">QWidget</a> * <i>editor</i>, const <a href="qmodelindex.html">QModelIndex</a> & <i>index</i> ) const <tt> [virtual]</tt></h3>
99
<p>Sets the data to be displayed and edited by the <i>editor</i> for the item specified by <i>index</i>.</p>
100
<p>Reimplemented from <a href="qabstractitemdelegate.html#setEditorData">QAbstractItemDelegate</a>.</p>
101
<h3 class="fn"><a name="setItemEditorFactory"></a>void QItemDelegate::setItemEditorFactory ( <a href="qitemeditorfactory.html">QItemEditorFactory</a> * <i>factory</i> )</h3>
102
<p>Sets the editor factory to be used by the item delegate to be the <i>factory</i> specified. If no editor factory is set, the item delegate will use the default editor factory.</p>
103
<h3 class="fn"><a name="setModelData"></a>void QItemDelegate::setModelData ( <a href="qwidget.html">QWidget</a> * <i>editor</i>, <a href="qabstractitemmodel.html">QAbstractItemModel</a> * <i>model</i>, const <a href="qmodelindex.html">QModelIndex</a> & <i>index</i> ) const <tt> [virtual]</tt></h3>
104
<p>Sets the data for the specified <i>model</i> and item <i>index</i> from that supplied by the <i>editor</i>.</p>
105
<p>Reimplemented from <a href="qabstractitemdelegate.html#setModelData">QAbstractItemDelegate</a>.</p>
106
<h3 class="fn"><a name="sizeHint"></a><a href="qsize.html">QSize</a> QItemDelegate::sizeHint ( const <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a> & <i>option</i>, const <a href="qmodelindex.html">QModelIndex</a> & <i>index</i> ) const <tt> [virtual]</tt></h3>
107
<p>Returns the size needed by the delegate to display the item specified by <i>index</i>, taking into account the style information provided by <i>option</i>.</p>
108
<p>Reimplemented from <a href="qabstractitemdelegate.html#sizeHint">QAbstractItemDelegate</a>.</p>
109
<h3 class="fn"><a name="updateEditorGeometry"></a>void QItemDelegate::updateEditorGeometry ( <a href="qwidget.html">QWidget</a> * <i>editor</i>, const <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a> & <i>option</i>, const <a href="qmodelindex.html">QModelIndex</a> & <i>index</i> ) const <tt> [virtual]</tt></h3>
110
<p>Updates the <i>editor</i> for the item specified by <i>index</i> according to the style <i>option</i> given.</p>
111
<p>Reimplemented from <a href="qabstractitemdelegate.html#updateEditorGeometry">QAbstractItemDelegate</a>.</p>
112
<p /><address><hr /><div align="center">
113
<table width="100%" cellspacing="0" border="0"><tr class="address">
114
<td width="30%">Copyright © 2005 <a href="trolltech.html">Trolltech</a></td>
115
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
116
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
117
</tr></table></div></address></body>