File: qitemdelegate.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 (104 lines) | stat: -rw-r--r-- 20,703 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
100
101
102
103
104
<?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>QItemDelegate 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">QItemDelegate Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QItemDelegate class provides display and editing facilities for data items from a model. <a href="#details">More...</a></p>
<p>Inherits <a href="qabstractitemdelegate.html">QAbstractItemDelegate</a>.</p><p>Inherited by <a href="qsqlrelationaldelegate.html">QSqlRelationalDelegate</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qitemdelegate.html#QItemDelegate">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" />QRect <b><a href="qitemdelegate.html#check">check</a></b> (<i>self</i>, QStyleOptionViewItem&#160;<i>option</i>, QRect&#160;<i>bounding</i>, QVariant&#160;<i>variant</i>)</li><li><div class="fn" />QWidget <b><a href="qitemdelegate.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" />QPixmap <b><a href="qitemdelegate.html#decoration">decoration</a></b> (<i>self</i>, QStyleOptionViewItem&#160;<i>option</i>, QVariant&#160;<i>variant</i>)</li><li><div class="fn" /><b><a href="qitemdelegate.html#doLayout">doLayout</a></b> (<i>self</i>, QStyleOptionViewItem&#160;<i>option</i>, QRect&#160;<i>checkRect</i>, QRect&#160;<i>iconRect</i>, QRect&#160;<i>textRect</i>, bool&#160;<i>hint</i>)</li><li><div class="fn" /><b><a href="qitemdelegate.html#drawCheck">drawCheck</a></b> (<i>self</i>, QPainter&#160;<i>painter</i>, QStyleOptionViewItem&#160;<i>option</i>, QRect&#160;<i>rect</i>, Qt.CheckState&#160;<i>state</i>)</li><li><div class="fn" /><b><a href="qitemdelegate.html#drawDecoration">drawDecoration</a></b> (<i>self</i>, QPainter&#160;<i>painter</i>, QStyleOptionViewItem&#160;<i>option</i>, QRect&#160;<i>rect</i>, QPixmap&#160;<i>pixmap</i>)</li><li><div class="fn" /><b><a href="qitemdelegate.html#drawDisplay">drawDisplay</a></b> (<i>self</i>, QPainter&#160;<i>painter</i>, QStyleOptionViewItem&#160;<i>option</i>, QRect&#160;<i>rect</i>, QString&#160;<i>text</i>)</li><li><div class="fn" /><b><a href="qitemdelegate.html#drawFocus">drawFocus</a></b> (<i>self</i>, QPainter&#160;<i>painter</i>, QStyleOptionViewItem&#160;<i>option</i>, QRect&#160;<i>rect</i>)</li><li><div class="fn" />bool <b><a href="qitemdelegate.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" />bool <b><a href="qitemdelegate.html#eventFilter">eventFilter</a></b> (<i>self</i>, QObject&#160;<i>object</i>, QEvent&#160;<i>event</i>)</li><li><div class="fn" />QItemEditorFactory <b><a href="qitemdelegate.html#itemEditorFactory">itemEditorFactory</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qitemdelegate.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" />QPixmap <b><a href="qitemdelegate.html#selected">selected</a></b> (<i>self</i>, QPixmap&#160;<i>pixmap</i>, QPalette&#160;<i>palette</i>, bool&#160;<i>enabled</i>)</li><li><div class="fn" /><b><a href="qitemdelegate.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="qitemdelegate.html#setItemEditorFactory">setItemEditorFactory</a></b> (<i>self</i>, QItemEditorFactory&#160;<i>factory</i>)</li><li><div class="fn" /><b><a href="qitemdelegate.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="qitemdelegate.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="qitemdelegate.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><a name="details" /><hr /><h2>Detailed Description</h2><p>The QItemDelegate class provides display and editing facilities for data items from a model.</p>
<p>QItemDelegate can be used to provide custom display features and editor widgets for item views based on <a href="qabstractitemview.html">QAbstractItemView</a> subclasses. Using a delegate for this purpose allows the display and editing mechanisms to be customized and developed independently from the model and view.</p>
<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>
<p>When displaying items from a custom model in a standard view, it is often sufficient to simply ensure that the model returns appropriate data for each of the <a href="qt.html#ItemDataRole-enum">roles</a> that determine the appearance of items in views. The default delegate used by Qt's standard views uses this role information to display items in most of the common forms expected by users. However, it is sometimes necessary to have even more control over the appearance of items than the default delegate can provide.</p>
<p>This class provides default implementations of the functions for painting item data in a view, and editing data obtained from a model. Default implementations of 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 provided to ensure that the delegate implements the correct basic behavior expected by views. You can reimplement these functions in subclasses to customize the appearance of items.</p>
<p>Delegates can be used to manipulate item 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>
<p>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>
<a id="standard-roles-and-data-types" name="standard-roles-and-data-types" />
<h3>Standard Roles and Data Types</h3>
<p>The default delegate used by the standard views supplied with Qt associates each standard role (defined by <a href="qt.html#ItemDataRole-enum">Qt.ItemDataRole</a>) with certain data types. Models that return data in these types can influence the appearance of the delegate as described in the following table.</p>
<table align="center" border="0" cellpadding="2" cellspacing="1">
<tr bgcolor="#A2C511" valign="top">
<th>Role</th>
<th>Accepted Types</th>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td><a href="qt.html#ItemDataRole-enum">Qt.BackgroundColorRole</a></td>
<td><a href="qcolor.html">QColor</a></td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td><a href="qt.html#ItemDataRole-enum">Qt.CheckStateRole</a></td>
<td><a href="qt.html#CheckState-enum">Qt.CheckState</a></td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td><a href="qt.html#ItemDataRole-enum">Qt.DecorationRole</a></td>
<td><a href="qicon.html">QIcon</a> and <a href="qcolor.html">QColor</a></td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td><a href="qt.html#ItemDataRole-enum">Qt.DisplayRole</a></td>
<td><a href="qstring.html">QString</a> and types with a string representation</td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td><a href="qt.html#ItemDataRole-enum">Qt.EditRole</a></td>
<td>See <a href="qitemeditorfactory.html">QItemEditorFactory</a> for details</td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td><a href="qt.html#ItemDataRole-enum">Qt.FontRole</a></td>
<td><a href="qfont.html">QFont</a></td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td><a href="qt.html#ItemDataRole-enum">Qt.SizeHintRole</a></td>
<td><a href="qsize.html">QSize</a></td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td><a href="qt.html#ItemDataRole-enum">Qt.TextAlignmentRole</a></td>
<td><a href="qt.html#AlignmentFlag-enum">Qt.Alignment</a></td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td><a href="qt.html#ItemDataRole-enum">Qt.TextColorRole</a></td>
<td><a href="qcolor.html">QColor</a></td>
</tr>
</table>
<br />
<br />
<p>If the default delegate does not allow the level of customization that you need, it is possible to subclass QItemDelegate to implement the desired behavior.</p>
<a id="subclassing" name="subclassing" />
<h3>Subclassing</h3>
<p>When subclassing QItemDelegate to create a delegate that displays items using a custom renderer, it is important to ensure that the delegate can render items suitably for all the required states; e.g. selected, disabled, checked. The documentation for the <a href="qitemdelegate.html#paint">paint</a>() function contains some hints to show how this can be achieved.</p>
<p>See also <a href="model-view-programming.html">Model/View Programming</a> and <a href="qabstractitemdelegate.html">QAbstractItemDelegate</a>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QItemDelegate" />QItemDelegate.__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>Constructs an item delegate with the given <i>parent</i>.</p>
<h3 class="fn"><a name="check" /><a href="qrect.html">QRect</a> QItemDelegate.check (<i>self</i>, <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a>&#160;<i>option</i>, <a href="qrect.html">QRect</a>&#160;<i>bounding</i>, <a href="qvariant.html">QVariant</a>&#160;<i>variant</i>)</h3><h3 class="fn"><a name="createEditor" /><a href="qwidget.html">QWidget</a> QItemDelegate.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 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>
<p>Reimplemented from <a href="qabstractitemdelegate.html#createEditor">QAbstractItemDelegate</a>.</p>
<p>See also <a href="qabstractitemdelegate.html#createEditor">QAbstractItemDelegate.createEditor</a>().</p>
<h3 class="fn"><a name="decoration" /><a href="qpixmap.html">QPixmap</a> QItemDelegate.decoration (<i>self</i>, <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a>&#160;<i>option</i>, <a href="qvariant.html">QVariant</a>&#160;<i>variant</i>)</h3><h3 class="fn"><a name="doLayout" />QItemDelegate.doLayout (<i>self</i>, <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a>&#160;<i>option</i>, <a href="qrect.html">QRect</a>&#160;<i>checkRect</i>, <a href="qrect.html">QRect</a>&#160;<i>iconRect</i>, <a href="qrect.html">QRect</a>&#160;<i>textRect</i>, bool&#160;<i>hint</i>)</h3><h3 class="fn"><a name="drawCheck" />QItemDelegate.drawCheck (<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="qrect.html">QRect</a>&#160;<i>rect</i>, <a href="qt.html#CheckState-enum">Qt.CheckState</a>&#160;<i>state</i>)</h3><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>
<h3 class="fn"><a name="drawDecoration" />QItemDelegate.drawDecoration (<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="qrect.html">QRect</a>&#160;<i>rect</i>, <a href="qpixmap.html">QPixmap</a>&#160;<i>pixmap</i>)</h3><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>
<h3 class="fn"><a name="drawDisplay" />QItemDelegate.drawDisplay (<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="qrect.html">QRect</a>&#160;<i>rect</i>, <a href="qstring.html">QString</a>&#160;<i>text</i>)</h3><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>
<h3 class="fn"><a name="drawFocus" />QItemDelegate.drawFocus (<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="qrect.html">QRect</a>&#160;<i>rect</i>)</h3><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>
<h3 class="fn"><a name="editorEvent" />bool QItemDelegate.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><h3 class="fn"><a name="eventFilter" />bool QItemDelegate.eventFilter (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>object</i>, <a href="qevent.html">QEvent</a>&#160;<i>event</i>)</h3><p>If the <i>object</i> is the current editor: if the <i>event</i> is an Esc key press the current edit is cancelled and ended, or if the <i>event</i> is an Enter or Return key press the current edit is accepted and ended. If editing is ended the event filter returns true to signify that it has handled the event; in all other cases it does nothing and returns false to signify that the event hasn't been handled.</p>
<p>Reimplemented from <a href="qobject.html#eventFilter">QObject</a>.</p>
<p>See also <a href="qabstractitemdelegate.html#closeEditor">closeEditor</a>().</p>
<h3 class="fn"><a name="itemEditorFactory" /><a href="qitemeditorfactory.html">QItemEditorFactory</a> QItemDelegate.itemEditorFactory (<i>self</i>)</h3><p>Returns the editor factory used by the item delegate. If no editor factory is set, the function will return null.</p>
<p>See also <a href="qitemdelegate.html#setItemEditorFactory">setItemEditorFactory</a>().</p>
<h3 class="fn"><a name="paint" />QItemDelegate.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>Renders the delegate using the given <i>painter</i> and style <i>option</i> for the item specified by <i>index</i>.</p>
<p>When reimplementing this function in a subclass, you should update the area held by the option's <a href="qstyleoption.html#rect-var">rect</a> variable, using the option's <a href="qstyleoption.html#state-var">state</a> variable to determine the state of the item to be displayed, and adjust the way it is painted accordingly.</p>
<p>For example, a selected item may need to be displayed differently to unselected items, as shown in the following code:</p>
<pre>
        if (option.state &amp; QStyle.State_Selected)
            painter-&gt;setBrush(option.palette.highlight());
        else
        ...
</pre>
<p>After painting, you should ensure that the painter is returned to its the state it was supplied in when this function was called. For example, it may be useful to call <a href="qpainter.html#save">QPainter.save</a>() before painting and <a href="qpainter.html#restore">QPainter.restore</a>() afterwards.</p>
<p>Reimplemented from <a href="qabstractitemdelegate.html#paint">QAbstractItemDelegate</a>.</p>
<p>See also <a href="qstyle.html#StateFlag-enum">QStyle.State</a>.</p>
<h3 class="fn"><a name="selected" /><a href="qpixmap.html">QPixmap</a> QItemDelegate.selected (<i>self</i>, <a href="qpixmap.html">QPixmap</a>&#160;<i>pixmap</i>, <a href="qpalette.html">QPalette</a>&#160;<i>palette</i>, bool&#160;<i>enabled</i>)</h3><h3 class="fn"><a name="setEditorData" />QItemDelegate.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 data to be displayed and edited by the <i>editor</i> for the item specified by <i>index</i>.</p>
<p>Reimplemented from <a href="qabstractitemdelegate.html#setEditorData">QAbstractItemDelegate</a>.</p>
<h3 class="fn"><a name="setItemEditorFactory" />QItemDelegate.setItemEditorFactory (<i>self</i>, <a href="qitemeditorfactory.html">QItemEditorFactory</a>&#160;<i>factory</i>)</h3><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>
<p>See also <a href="qitemdelegate.html#itemEditorFactory">itemEditorFactory</a>().</p>
<h3 class="fn"><a name="setModelData" />QItemDelegate.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 specified <i>model</i> and item <i>index</i> from that supplied by the <i>editor</i>.</p>
<p>Reimplemented from <a href="qabstractitemdelegate.html#setModelData">QAbstractItemDelegate</a>.</p>
<h3 class="fn"><a name="sizeHint" /><a href="qsize.html">QSize</a> QItemDelegate.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>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>
<p>Reimplemented from <a href="qabstractitemdelegate.html#sizeHint">QAbstractItemDelegate</a>.</p>
<h3 class="fn"><a name="updateEditorGeometry" />QItemDelegate.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 <i>editor</i> for the item specified by <i>index</i> according to the style <i>option</i> given.</p>
<p>Reimplemented from <a href="qabstractitemdelegate.html#updateEditorGeometry">QAbstractItemDelegate</a>.</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>