File: qstandarditemmodel.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 (84 lines) | stat: -rw-r--r-- 18,537 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
<?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>QStandardItemModel 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">QStandardItemModel Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QStandardItemModel class provides a generic model for storing custom data. <a href="#details">More...</a></p>
<p>Inherits <a href="qabstractitemmodel.html">QAbstractItemModel</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qstandarditemmodel.html#QStandardItemModel">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" /><b><a href="qstandarditemmodel.html#QStandardItemModel-2">__init__</a></b> (<i>self</i>, int&#160;<i>rows</i>, int&#160;<i>columns</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" /><b><a href="qstandarditemmodel.html#clear">clear</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qstandarditemmodel.html#columnCount">columnCount</a></b> (<i>self</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" />QVariant <b><a href="qstandarditemmodel.html#data">data</a></b> (<i>self</i>, QModelIndex&#160;<i>index</i>, int&#160;<i>role</i>&#160;=&#160;Qt.DisplayRole)</li><li><div class="fn" />Qt.ItemFlags <b><a href="qstandarditemmodel.html#flags">flags</a></b> (<i>self</i>, QModelIndex&#160;<i>index</i>)</li><li><div class="fn" />bool <b><a href="qstandarditemmodel.html#hasChildren">hasChildren</a></b> (<i>self</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" />QVariant <b><a href="qstandarditemmodel.html#headerData">headerData</a></b> (<i>self</i>, int&#160;<i>section</i>, Qt.Orientation&#160;<i>orientation</i>, int&#160;<i>role</i>&#160;=&#160;Qt.DisplayRole)</li><li><div class="fn" />QModelIndex <b><a href="qstandarditemmodel.html#index">index</a></b> (<i>self</i>, int&#160;<i>row</i>, int&#160;<i>column</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" />bool <b><a href="qstandarditemmodel.html#insertColumns">insertColumns</a></b> (<i>self</i>, int&#160;<i>column</i>, int&#160;<i>count</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" />bool <b><a href="qstandarditemmodel.html#insertRows">insertRows</a></b> (<i>self</i>, int&#160;<i>row</i>, int&#160;<i>count</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" />QModelIndex <b><a href="qstandarditemmodel.html#parent">parent</a></b> (<i>self</i>, QModelIndex&#160;<i>child</i>)</li><li><div class="fn" />QObject <b><a href="qstandarditemmodel.html#parent-2">parent</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qstandarditemmodel.html#removeColumns">removeColumns</a></b> (<i>self</i>, int&#160;<i>column</i>, int&#160;<i>count</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" />bool <b><a href="qstandarditemmodel.html#removeRows">removeRows</a></b> (<i>self</i>, int&#160;<i>row</i>, int&#160;<i>count</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" />int <b><a href="qstandarditemmodel.html#rowCount">rowCount</a></b> (<i>self</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" />bool <b><a href="qstandarditemmodel.html#setData">setData</a></b> (<i>self</i>, QModelIndex&#160;<i>index</i>, QVariant&#160;<i>value</i>, int&#160;<i>role</i>&#160;=&#160;Qt.EditRole)</li><li><div class="fn" />bool <b><a href="qstandarditemmodel.html#setHeaderData">setHeaderData</a></b> (<i>self</i>, int&#160;<i>section</i>, Qt.Orientation&#160;<i>orientation</i>, QVariant&#160;<i>value</i>, int&#160;<i>role</i>&#160;=&#160;Qt.EditRole)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QStandardItemModel class provides a generic model for storing custom data.</p>
<p>QStandardItemModel can be used as a repository for standard Qt data types. It 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</a> framework.</p>
<p>Data is written to the model, and read back, using the standard <a href="qabstractitemmodel.html">QAbstractItemModel</a> interface. The way each item of information is referenced depends on how the data is inserted into the model. The QStandardItemModel class reimplements several of the <a href="qabstractitemmodel.html">QAbstractItemModel</a> class's functions, and implements in addition a <a href="qstandarditemmodel.html#clear">clear</a>() function which removes all items from the model and resets both the horizontal and vertical headers.</p>
<p>For performance and flexibility, you may want to subclass <a href="qabstractitemmodel.html">QAbstractItemModel</a> to provide support for different kinds of repositories. For example, the <a href="qdirmodel.html">QDirModel</a> provides a model interface to the underlying file system, and does not actually store file information internally.</p>
<p>An example usage of QStandardItemModel to create a table:</p>
<pre>
        QStandardItemModel model(4, 2);
        for (int row = 0; row &lt; 4; ++row) {
            for (int column = 0; column &lt; 2; ++column) {
                QModelIndex index = model.index(row, column, QModelIndex());
                model.setData(index, QVariant((row+1) * (column+1)));
            }
        }
</pre>
<p>An example usage of QStandardItemModel to create a tree:</p>
<pre>
        QStandardItemModel *model = new QStandardItemModel();
        QModelIndex parent;
        for (int i = 0; i &lt; 4; ++i) {
            parent = model-&gt;index(0, 0, parent);
            model-&gt;insertRows(0, 1, parent);
            model-&gt;insertColumns(0, 1, parent);
            QModelIndex index = model-&gt;index(0, 0, parent);
            model-&gt;setData(index, i);
        }
</pre>
<p>The current implementation of QStandardItemModel only supports adding children to the first column.</p>
<p>See also <a href="model-view-programming.html">Model/View Programming</a>, <a href="qabstractitemmodel.html">QAbstractItemModel</a>, and <a href="itemviews-simpletreemodel.html">Simple Tree Model example</a>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QStandardItemModel" />QStandardItemModel.__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 an empty model with the given <i>parent</i>, containing no rows or columns.</p>
<p>See also <a href="qstandarditemmodel.html#insertColumns">insertColumns</a>() and <a href="qstandarditemmodel.html#insertRows">insertRows</a>().</p>
<h3 class="fn"><a name="QStandardItemModel-2" />QStandardItemModel.__init__ (<i>self</i>, int&#160;<i>rows</i>, int&#160;<i>columns</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 model with the given <i>parent</i>, containing the given number of <i>rows</i> and <i>columns</i>.</p>
<p>See also <a href="qstandarditemmodel.html#columnCount">columnCount</a>() and <a href="qstandarditemmodel.html#rowCount">rowCount</a>().</p>
<h3 class="fn"><a name="clear" />QStandardItemModel.clear (<i>self</i>)</h3><p>Removes all items from the model and resets both the horizontal and vertical headers.</p>
<p>See also <a href="qstandarditemmodel.html#removeColumns">removeColumns</a>() and <a href="qstandarditemmodel.html#removeRows">removeRows</a>().</p>
<h3 class="fn"><a name="columnCount" />int QStandardItemModel.columnCount (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><p>Returns the number of columns in the model that contain items with the given <i>parent</i>.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#columnCount">QAbstractItemModel</a>.</p>
<p>See also <a href="qstandarditemmodel.html#rowCount">rowCount</a>() and <a href="qstandarditemmodel.html#insertColumns">insertColumns</a>().</p>
<h3 class="fn"><a name="data" /><a href="qvariant.html">QVariant</a> QStandardItemModel.data (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>, int&#160;<i>role</i>&#160;=&#160;Qt.DisplayRole)</h3><p>Returns the data for the given <i>index</i> and display <i>role</i>.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#data">QAbstractItemModel</a>.</p>
<p>See also <a href="qstandarditemmodel.html#setData">setData</a>(), <a href="qabstractitemmodel.html#setHeaderData">setHeaderData</a>(), and <a href="qstandarditemmodel.html#index">index</a>().</p>
<h3 class="fn"><a name="flags" /><a href="qt-itemflags.html">Qt.ItemFlags</a> QStandardItemModel.flags (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>)</h3><p>Returns the item flags for the given <i>index</i>.</p>
<p>This model returns returns a combination of flags that enables the item (<a href="qt.html#ItemFlag-enum">Qt.ItemIsEnabled</a>), allows it to be selected (<a href="qt.html#ItemFlag-enum">Qt.ItemIsSelectable</a>) and edited (<a href="qt.html#ItemFlag-enum">Qt.ItemIsEditable</a>).</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#flags">QAbstractItemModel</a>.</p>
<p>See also <a href="qt.html#ItemFlag-enum">Qt.ItemFlags</a>.</p>
<h3 class="fn"><a name="hasChildren" />bool QStandardItemModel.hasChildren (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><p>Returns true if the given <i>parent</i> model index has child items; otherwise returns false.</p>
<p>Use the <a href="qstandarditemmodel.html#insertColumns">insertColumns</a>() and <a href="qstandarditemmodel.html#insertRows">insertRows</a>() functions to add children.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#hasChildren">QAbstractItemModel</a>.</p>
<p>See also <a href="qstandarditemmodel.html#rowCount">rowCount</a>(), <a href="qstandarditemmodel.html#columnCount">columnCount</a>(), and <a href="qstandarditemmodel.html#parent">parent</a>().</p>
<h3 class="fn"><a name="headerData" /><a href="qvariant.html">QVariant</a> QStandardItemModel.headerData (<i>self</i>, int&#160;<i>section</i>, <a href="qt.html#Orientation-enum">Qt.Orientation</a>&#160;<i>orientation</i>, int&#160;<i>role</i>&#160;=&#160;Qt.DisplayRole)</h3><h3 class="fn"><a name="index" /><a href="qmodelindex.html">QModelIndex</a> QStandardItemModel.index (<i>self</i>, int&#160;<i>row</i>, int&#160;<i>column</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><p>Returns the index of the item in the model specified by the given <i>row</i>, <i>column</i>, and <i>parent</i> index.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#index">QAbstractItemModel</a>.</p>
<p>See also <a href="qstandarditemmodel.html#data">data</a>().</p>
<h3 class="fn"><a name="insertColumns" />bool QStandardItemModel.insertColumns (<i>self</i>, int&#160;<i>column</i>, int&#160;<i>count</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><p>Inserts <i>count</i> columns into the model, creating new items as children of the given <i>parent</i>. The new columns are inserted before the <i>column</i> specified. Returns true if the columns were successfully inserted; otherwise returns false.</p>
<p>If <i>column</i> is 0, the columns are prepended to any existing columns in the parent. If <i>column</i> is <a href="qstandarditemmodel.html#columnCount">columnCount</a>(), the columns are appended to any existing columns in the parent. If the given <i>parent</i> has no children, a single row with <i>count</i> columns is inserted.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#insertColumns">QAbstractItemModel</a>.</p>
<p>See also <a href="qabstractitemmodel.html#insertColumn">insertColumn</a>(), <a href="qstandarditemmodel.html#insertRows">insertRows</a>(), <a href="qstandarditemmodel.html#removeColumns">removeColumns</a>(), and <a href="qstandarditemmodel.html#columnCount">columnCount</a>().</p>
<h3 class="fn"><a name="insertRows" />bool QStandardItemModel.insertRows (<i>self</i>, int&#160;<i>row</i>, int&#160;<i>count</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><p>Inserts <i>count</i> rows into the model, creating new items as children of the given <i>parent</i>. The new rows are inserted before the <i>row</i> specified. Returns true if the rows were successfully inserted; otherwise returns false.</p>
<p>If <i>row</i> is 0, the rows are prepended to any existing rows in the parent. If <i>row</i> is <a href="qstandarditemmodel.html#rowCount">rowCount</a>(), the rows are appended to any existing rows in the parent. If the given <i>parent</i> has no children, a single column with <i>count</i> rows is inserted. Note that a row with no columns will not show up in the treeview.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#insertRows">QAbstractItemModel</a>.</p>
<p>See also <a href="qabstractitemmodel.html#insertRow">insertRow</a>(), <a href="qstandarditemmodel.html#insertColumns">insertColumns</a>(), <a href="qstandarditemmodel.html#removeRows">removeRows</a>(), and <a href="qstandarditemmodel.html#rowCount">rowCount</a>().</p>
<h3 class="fn"><a name="parent" /><a href="qmodelindex.html">QModelIndex</a> QStandardItemModel.parent (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>child</i>)</h3><p>Returns the model index for the parent of the given <i>child</i> item.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#parent">QAbstractItemModel</a>.</p>
<p>See also <a href="qstandarditemmodel.html#hasChildren">hasChildren</a>().</p>
<h3 class="fn"><a name="parent-2" /><a href="qobject.html">QObject</a> QStandardItemModel.parent (<i>self</i>)</h3><h3 class="fn"><a name="removeColumns" />bool QStandardItemModel.removeColumns (<i>self</i>, int&#160;<i>column</i>, int&#160;<i>count</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><p>Removes <i>count</i> columns from the model, starting with the specified <i>column</i>. The items removed are children of the item represented by the given <i>parent</i> model index. Returns true if the columns were successfully removed; otherwise returns false.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#removeColumns">QAbstractItemModel</a>.</p>
<p>See also <a href="qstandarditemmodel.html#clear">clear</a>(), <a href="qstandarditemmodel.html#insertColumns">insertColumns</a>(), and <a href="qstandarditemmodel.html#columnCount">columnCount</a>().</p>
<h3 class="fn"><a name="removeRows" />bool QStandardItemModel.removeRows (<i>self</i>, int&#160;<i>row</i>, int&#160;<i>count</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><p>Removes <i>count</i> rows from the model, starting with the specified <i>row</i>. The items removed are children of the item represented by the given <i>parent</i> model index. Returns true if the rows were successfully removed; otherwise returns false.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#removeRows">QAbstractItemModel</a>.</p>
<p>See also <a href="qstandarditemmodel.html#clear">clear</a>(), <a href="qstandarditemmodel.html#insertRows">insertRows</a>(), and <a href="qstandarditemmodel.html#rowCount">rowCount</a>().</p>
<h3 class="fn"><a name="rowCount" />int QStandardItemModel.rowCount (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><p>Returns the number of rows in the model that contain items with the given <i>parent</i>.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#rowCount">QAbstractItemModel</a>.</p>
<p>See also <a href="qstandarditemmodel.html#columnCount">columnCount</a>() and <a href="qstandarditemmodel.html#insertRows">insertRows</a>().</p>
<h3 class="fn"><a name="setData" />bool QStandardItemModel.setData (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>, <a href="qvariant.html">QVariant</a>&#160;<i>value</i>, int&#160;<i>role</i>&#160;=&#160;Qt.EditRole)</h3><p>Sets the data for the given <i>index</i> and <i>role</i> to the <i>value</i> specified. The role is described by the <a href="qt.html#ItemDataRole-enum">Qt.ItemDataRole</a> enum. Returns false if the given <i>index</i> is not valid; otherwise returns true.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#setData">QAbstractItemModel</a>.</p>
<p>See also <a href="qstandarditemmodel.html#data">data</a>(), <a href="qabstractitemmodel.html#itemData">itemData</a>(), and <a href="qabstractitemmodel.html#setHeaderData">setHeaderData</a>().</p>
<h3 class="fn"><a name="setHeaderData" />bool QStandardItemModel.setHeaderData (<i>self</i>, int&#160;<i>section</i>, <a href="qt.html#Orientation-enum">Qt.Orientation</a>&#160;<i>orientation</i>, <a href="qvariant.html">QVariant</a>&#160;<i>value</i>, int&#160;<i>role</i>&#160;=&#160;Qt.EditRole)</h3><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>