File: qabstractitemdelegate.html

package info (click to toggle)
python-qt4 4.0.1-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,632 kB
  • ctags: 2,639
  • sloc: python: 29,409; sh: 5,646; cpp: 3,168; xml: 149; makefile: 109
file content (99 lines) | stat: -rw-r--r-- 15,376 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QAbstractItemDelegate Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QAbstractItemDelegate Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QAbstractItemDelegate class is used to display and edit data items from a model. <a href="#details">More...</a></p>
<p>Inherits <a href="qobject.html">QObject</a>.</p><p>Inherited by <a href="qitemdelegate.html">QItemDelegate</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qabstractitemdelegate.html#EndEditHint-enum">EndEditHint</a></b> { NoHint, EditNextItem, EditPreviousItem, SubmitModelCache, RevertModelCache }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qabstractitemdelegate.html#QAbstractItemDelegate">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" />QWidget <b><a href="qabstractitemdelegate.html#createEditor">createEditor</a></b> (<i>self</i>, QWidget&#160;<i>parent</i>, QStyleOptionViewItem&#160;<i>option</i>, QModelIndex&#160;<i>index</i>)</li><li><div class="fn" />bool <b><a href="qabstractitemdelegate.html#editorEvent">editorEvent</a></b> (<i>self</i>, QEvent&#160;<i>event</i>, QAbstractItemModel&#160;<i>model</i>, QStyleOptionViewItem&#160;<i>option</i>, QModelIndex&#160;<i>index</i>)</li><li><div class="fn" /><b><a href="qabstractitemdelegate.html#paint">paint</a></b> (<i>self</i>, QPainter&#160;<i>painter</i>, QStyleOptionViewItem&#160;<i>option</i>, QModelIndex&#160;<i>index</i>)</li><li><div class="fn" /><b><a href="qabstractitemdelegate.html#setEditorData">setEditorData</a></b> (<i>self</i>, QWidget&#160;<i>editor</i>, QModelIndex&#160;<i>index</i>)</li><li><div class="fn" /><b><a href="qabstractitemdelegate.html#setModelData">setModelData</a></b> (<i>self</i>, QWidget&#160;<i>editor</i>, QAbstractItemModel&#160;<i>model</i>, QModelIndex&#160;<i>index</i>)</li><li><div class="fn" />QSize <b><a href="qabstractitemdelegate.html#sizeHint">sizeHint</a></b> (<i>self</i>, QStyleOptionViewItem&#160;<i>option</i>, QModelIndex&#160;<i>index</i>)</li><li><div class="fn" /><b><a href="qabstractitemdelegate.html#updateEditorGeometry">updateEditorGeometry</a></b> (<i>self</i>, QWidget&#160;<i>editor</i>, QStyleOptionViewItem&#160;<i>option</i>, QModelIndex&#160;<i>index</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QString <b><a href="qabstractitemdelegate.html#elidedText">elidedText</a></b> (QFontMetrics&#160;<i>fontMetrics</i>, int&#160;<i>width</i>, Qt.TextElideMode&#160;<i>mode</i>, QString&#160;<i>text</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qabstractitemdelegate.html#closeEditor">closeEditor</a></b> (QWidget *,QAbstractItemDelegate::EndEditHint = QAbstractItemDelegate.NoHint)</li><li><div class="fn" />void <b><a href="qabstractitemdelegate.html#commitData">commitData</a></b> (QWidget *)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QAbstractItemDelegate class is used to display and edit data items from a model.</p>
<p>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.</p>
<p>The QAbstractItemDelegate 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>
<p>To render an item in a custom way, you must implement <a href="qabstractitemdelegate.html#paint">paint</a>() and <a href="qabstractitemdelegate.html#sizeHint">sizeHint</a>(). The <a href="qitemdelegate.html">QItemDelegate</a> class provides default implementations for these functions; if you do not need custom rendering, subclass that class instead.</p>
<p>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 <a href="qabstractitemdelegate.html#createEditor">createEditor</a>() to provide an editor widget, <a href="qabstractitemdelegate.html#setEditorData">setEditorData</a>() to populate the editor with the data from the model, and <a href="qabstractitemdelegate.html#setModelData">setModelData</a>() so that the delegate can update the model with data from the editor.</p>
<p>The second approach is to handle user events directly by reimplementing <a href="qabstractitemdelegate.html#editorEvent">editorEvent</a>().</p>
<p>See also <a href="model-view-programming.html">Model/View Programming</a> and <a href="qitemdelegate.html">QItemDelegate</a>.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="EndEditHint-enum" />QAbstractItemDelegate.EndEditHint</h3><p>This enum describes the different hints that the delegate can give to the model and view components to make editing data in a model a comfortable experience for the user.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QAbstractItemDelegate.NoHint</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">There is no recommended action to be performed.</td>
</tr>
</table>
<br />
<br />
<p>These hints let the delegate influence the behavior of the view:</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QAbstractItemDelegate.EditNextItem</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">The view should use the delegate to open an editor on the next item in the view.</td>
</tr>
<tr>
<td valign="top"><tt>QAbstractItemDelegate.EditPreviousItem</tt></td>
<td align="center" valign="top"><tt>2</tt></td>
<td valign="top">The view should use the delegate to open an editor on the previous item in the view.</td>
</tr>
</table>
<br />
<br />
<p>Note that custom views may interpret the concepts of next and previous differently.</p>
<p>The following hints are most useful when models are used that cache data, such as those that manipulate date locally in order to increase performance or conserve network bandwidth.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QAbstractItemDelegate.SubmitModelCache</tt></td>
<td align="center" valign="top"><tt>3</tt></td>
<td valign="top">If the model caches data, it should write out cached data to the underlying data store.</td>
</tr>
<tr>
<td valign="top"><tt>QAbstractItemDelegate.RevertModelCache</tt></td>
<td align="center" valign="top"><tt>4</tt></td>
<td valign="top">If the model caches data, it should discard cached data and replace it with data from the underlying data store.</td>
</tr>
</table>
<br />
<br />
<p>Although models and views should respond to these hints in appropriate ways, custom components may ignore any or all of them if they are not relevant.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QAbstractItemDelegate" />QAbstractItemDelegate.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Creates a new abstract item delegate with the given <i>parent</i>.</p>
<h3 class="fn"><a name="createEditor" /><a href="qwidget.html">QWidget</a> QAbstractItemDelegate.createEditor (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>parent</i>, <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a>&#160;<i>option</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>)</h3><p>Returns the editor to be used for editing the data item with the given <i>index</i>. Note that the index contains information about the model being used. The editor's parent widget is specified by <i>parent</i>, and the item options by <i>option</i>.</p>
<p>The base implementation returns 0. If you want custom editing you will need to reimplement this function.</p>
<p>See also <a href="qabstractitemdelegate.html#setModelData">setModelData</a>() and <a href="qabstractitemdelegate.html#setEditorData">setEditorData</a>().</p>
<h3 class="fn"><a name="editorEvent" />bool QAbstractItemDelegate.editorEvent (<i>self</i>, <a href="qevent.html">QEvent</a>&#160;<i>event</i>, <a href="qabstractitemmodel.html">QAbstractItemModel</a>&#160;<i>model</i>, <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a>&#160;<i>option</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>)</h3><p>Whenever an event occurs, this function is called with the <i>event</i> <i>model</i> <i>option</i> and the <i>index</i> that corresponds to the item being edited.</p>
<p>The base implementation returns false (indicating that it has not handled the event).</p>
<h3 class="fn"><a name="elidedText" /><a href="qstring.html">QString</a> QAbstractItemDelegate.elidedText (<a href="qfontmetrics.html">QFontMetrics</a>&#160;<i>fontMetrics</i>, int&#160;<i>width</i>, <a href="qt.html#TextElideMode-enum">Qt.TextElideMode</a>&#160;<i>mode</i>, <a href="qstring.html">QString</a>&#160;<i>text</i>)</h3><p>If the string <i>text</i> is wider than <i>width</i>, returns an elided version of the string (i.e., a string with "..." in it). Otherwise, returns the original string.</p>
<p>The <i>mode</i> parameter specifies whether the text is elided on the left (e.g., "...tech"), in the middle (e.g., "Tr...ch"), or on the right (e.g., "Trol...").</p>
<p>The <i>width</i> is specified in pixels, not characters. The font metrics to be used are given by <i>fontMetrics</i>.</p>
<h3 class="fn"><a name="paint" />QAbstractItemDelegate.paint (<i>self</i>, <a href="qpainter.html">QPainter</a>&#160;<i>painter</i>, <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a>&#160;<i>option</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>This pure abstract function must be reimplemented if you want to provide custom rendering. Use the <i>painter</i> and style <i>option</i> to render the item specified by the item <i>index</i>.</p>
<p>If you reimplement this you must also reimplement <a href="qabstractitemdelegate.html#sizeHint">sizeHint</a>().</p>
<h3 class="fn"><a name="setEditorData" />QAbstractItemDelegate.setEditorData (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>editor</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>)</h3><p>Sets the contents of the given <i>editor</i> to the data for the item at the given <i>index</i>. Note that the index contains information about the model being used.</p>
<p>The base implementation does nothing. If you want custom editing you will need to reimplement this function.</p>
<p>See also <a href="qabstractitemdelegate.html#setModelData">setModelData</a>().</p>
<h3 class="fn"><a name="setModelData" />QAbstractItemDelegate.setModelData (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>editor</i>, <a href="qabstractitemmodel.html">QAbstractItemModel</a>&#160;<i>model</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>)</h3><p>Sets the data for the item at the given <i>index</i> in the <i>model</i> to the contents of the given <i>editor</i>.</p>
<p>The base implementation does nothing. If you want custom editing you will need to reimplement this function.</p>
<p>See also <a href="qabstractitemdelegate.html#setEditorData">setEditorData</a>().</p>
<h3 class="fn"><a name="sizeHint" /><a href="qsize.html">QSize</a> QAbstractItemDelegate.sizeHint (<i>self</i>, <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a>&#160;<i>option</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>This pure abstract function must be reimplemented if you want to provide custom rendering. The options are specified by <i>option</i> and the model item by <i>index</i>.</p>
<p>If you reimplement this you must also reimplement <a href="qabstractitemdelegate.html#paint">paint</a>().</p>
<h3 class="fn"><a name="updateEditorGeometry" />QAbstractItemDelegate.updateEditorGeometry (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>editor</i>, <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a>&#160;<i>option</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>)</h3><p>Updates the geometry of the <i>editor</i> for the item with the given <i>index</i>, according to the rectangle specified in the <i>option</i>. If the item has an internal layout, the editor will be laid out accordingly. Note that the index contains information about the model being used.</p>
<p>The base implementation does nothing. If you want custom editing you must reimplement this function.</p>
<hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="closeEditor" />void closeEditor (QWidget *,QAbstractItemDelegate::EndEditHint = QAbstractItemDelegate.NoHint)</h3><p>This signal is emitted when the user has finished editing an item using the specified <i>editor</i>.</p>
<p>The <i>hint</i> provides a way for the delegate to influence how the model and view behave after editing is completed. It indicates to these components what action should be performed next to provide a comfortable editing experience for the user. For example, if <tt>EditNextItem</tt> is specified, the view should use a delegate to open an editor on the next item in the model.</p>
<p>See also <a href="qabstractitemdelegate.html#EndEditHint-enum">EndEditHint</a>.</p>
<h3 class="fn"><a name="commitData" />void commitData (QWidget *)</h3><p>This signal must be emitted when the <i>editor</i> widget has completed editing the data, and wants to write it back into the model.</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt&#160;4.0.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.trolltech.com">Trolltech&#160;AS</a> 2006</td><td align="right" width="25%">Qt&#160;4.1.4</td></tr></table></div></address></body></html>