<?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>QAbstractListModel 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">  </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="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QAbstractListModel Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QAbstractListModel class provides an abstract model that can be subclassed to create one-dimensional list models. <a href="#details">More...</a></p> <p>Inherits <a href="qabstractitemmodel.html">QAbstractItemModel</a>.</p><p>Inherited by <a href="phonon-audiooutputdevicemodel.html">AudioOutputDeviceModel</a>, <a href="phonon-effectdescriptionmodel.html">EffectDescriptionModel</a> and <a href="qstringlistmodel.html">QStringListModel</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qabstractlistmodel.html#QAbstractListModel">__init__</a></b> (<i>self</i>, QObject <i>parent</i> = None)</li><li><div class="fn" />bool <b><a href="qabstractlistmodel.html#dropMimeData">dropMimeData</a></b> (<i>self</i>, QMimeData <i>data</i>, Qt.DropAction <i>action</i>, int <i>row</i>, int <i>column</i>, QModelIndex <i>parent</i>)</li><li><div class="fn" />QModelIndex <b><a href="qabstractlistmodel.html#index">index</a></b> (<i>self</i>, int <i>row</i>, int <i>column</i> = 0, QModelIndex <i>parent</i> = QModelIndex())</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QAbstractListModel class provides an abstract model that can be subclassed to create one-dimensional list models.</p> <p>QAbstractListModel provides a standard interface for models that represent their data as a simple non-hierarchical sequence of items. It is not used directly, but must be subclassed.</p> <p>Since the model provides a more specialized interface than <a href="qabstractitemmodel.html">QAbstractItemModel</a>, it is not suitable for use with tree views; you will need to subclass <a href="qabstractitemmodel.html">QAbstractItemModel</a> if you want to provide a model for that purpose. If you need to use a number of list models to manage data, it may be more appropriate to subclass <a href="qabstracttablemodel.html">QAbstractTableModel</a> class instead.</p> <p>Simple models can be created by subclassing this class and implementing the minimum number of required functions. For example, we could implement a simple read-only <a href="qstringlist.html">QStringList</a>-based model that provides a list of strings to a <a href="qlistview.html">QListView</a> widget. In such a case, we only need to implement the <a href="qabstractitemmodel.html#rowCount">rowCount</a>() function to return the number of items in the list, and the <a href="qabstractitemmodel.html#data">data</a>() function to retrieve items from the list.</p> <p>Since the model represents a one-dimensional structure, the <a href="qabstractitemmodel.html#rowCount">rowCount</a>() function returns the total number of items in the model. The <a href="qabstractitemmodel.html#columnCount">columnCount</a>() function is implemented for interoperability with all kinds of views, but by default informs views that the model contains only one column.</p> <a id="subclassing" name="subclassing" /> <h3>Subclassing</h3> <p>When subclassing QAbstractListModel, you must provide implementations of the <a href="qabstractitemmodel.html#rowCount">rowCount</a>() and <a href="qabstractitemmodel.html#data">data</a>() functions. Well behaved models also provide a <a href="qabstractitemmodel.html#headerData">headerData</a>() implementation.</p> <p>For editable list models, you must also provide an implementation of <a href="qabstractitemmodel.html#setData">setData</a>(), implement the <a href="qabstractitemmodel.html#flags">flags</a>() function so that it returns a value containing <a href="qt.html#ItemFlag-enum">Qt.ItemIsEditable</a>.</p> <p>Note that QAbstractListModel provides a default implementation of <a href="qabstractitemmodel.html#columnCount">columnCount</a>() that informs views that there is only a single column of items in this model.</p> <p>Models that provide interfaces to resizable list-like data structures can provide implementations of <a href="qabstractitemmodel.html#insertRows">insertRows</a>() and <a href="qabstractitemmodel.html#removeRows">removeRows</a>(). When implementing these functions, it is important to call the appropriate functions so that all connected views are aware of any changes:</p> <ul> <li>An <a href="qabstractitemmodel.html#insertRows">insertRows</a>() implementation must call <a href="qabstractitemmodel.html#beginInsertRows">beginInsertRows</a>() <i>before</i> inserting new rows into the data structure, and it must call <a href="qabstractitemmodel.html#endInsertRows">endInsertRows</a>() <i>immediately afterwards</i>.</li> <li>A <a href="qabstractitemmodel.html#removeRows">removeRows</a>() implementation must call <a href="qabstractitemmodel.html#beginRemoveRows">beginRemoveRows</a>() <i>before</i> the rows are removed from the data structure, and it must call <a href="qabstractitemmodel.html#endRemoveRows">endRemoveRows</a>() <i>immediately afterwards</i>.</li> </ul> <p><b>Note:</b> Some general guidelines for subclassing models are available in the <a href="model-view-programming.html#model-subclassing-reference">Model Subclassing Reference</a>.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QAbstractListModel" />QAbstractListModel.__init__ (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i> = 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 abstract list model with the given <i>parent</i>.</p> <h3 class="fn"><a name="dropMimeData" />bool QAbstractListModel.dropMimeData (<i>self</i>, <a href="qmimedata.html">QMimeData</a> <i>data</i>, <a href="qt.html#DropAction-enum">Qt.DropAction</a> <i>action</i>, int <i>row</i>, int <i>column</i>, <a href="qmodelindex.html">QModelIndex</a> <i>parent</i>)</h3><p>Reimplemented from <a href="qabstractitemmodel.html#dropMimeData">QAbstractItemModel.dropMimeData</a>().</p> <h3 class="fn"><a name="index" /><a href="qmodelindex.html">QModelIndex</a> QAbstractListModel.index (<i>self</i>, int <i>row</i>, int <i>column</i> = 0, <a href="qmodelindex.html">QModelIndex</a> <i>parent</i> = QModelIndex())</h3><p>Reimplemented from <a href="qabstractitemmodel.html#index">QAbstractItemModel.index</a>().</p> <p>Returns the index of the data in <i>row</i> and <i>column</i> with <i>parent</i>.</p> <p><b>See also</b> <a href="qabstractitemmodel.html#parent">parent</a>().</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>