<?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>QItemSelectionModel 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">QItemSelectionModel Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QItemSelectionModel class keeps track of a view's selected items. <a href="#details">More...</a></p> <p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qitemselectionmodel.html#SelectionFlag-enum">SelectionFlag</a></b> { NoUpdate, Clear, Select, Deselect, ..., ClearAndSelect }</li><li><div class="fn" />class <b><a href="qitemselectionmodel-selectionflags.html">SelectionFlags</a></b></li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qitemselectionmodel.html#QItemSelectionModel">__init__</a></b> (<i>self</i>, QAbstractItemModel <i>model</i>)</li><li><div class="fn" /><b><a href="qitemselectionmodel.html#QItemSelectionModel-2">__init__</a></b> (<i>self</i>, QAbstractItemModel <i>model</i>, QObject <i>parent</i>)</li><li><div class="fn" /><b><a href="qitemselectionmodel.html#clear">clear</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qitemselectionmodel.html#clearSelection">clearSelection</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qitemselectionmodel.html#columnIntersectsSelection">columnIntersectsSelection</a></b> (<i>self</i>, int <i>column</i>, QModelIndex <i>parent</i>)</li><li><div class="fn" />QModelIndex <b><a href="qitemselectionmodel.html#currentIndex">currentIndex</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qitemselectionmodel.html#emitSelectionChanged">emitSelectionChanged</a></b> (<i>self</i>, QItemSelection <i>newSelection</i>, QItemSelection <i>oldSelection</i>)</li><li><div class="fn" />bool <b><a href="qitemselectionmodel.html#hasSelection">hasSelection</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qitemselectionmodel.html#isColumnSelected">isColumnSelected</a></b> (<i>self</i>, int <i>column</i>, QModelIndex <i>parent</i>)</li><li><div class="fn" />bool <b><a href="qitemselectionmodel.html#isRowSelected">isRowSelected</a></b> (<i>self</i>, int <i>row</i>, QModelIndex <i>parent</i>)</li><li><div class="fn" />bool <b><a href="qitemselectionmodel.html#isSelected">isSelected</a></b> (<i>self</i>, QModelIndex <i>index</i>)</li><li><div class="fn" />QAbstractItemModel <b><a href="qitemselectionmodel.html#model">model</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qitemselectionmodel.html#reset">reset</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qitemselectionmodel.html#rowIntersectsSelection">rowIntersectsSelection</a></b> (<i>self</i>, int <i>row</i>, QModelIndex <i>parent</i>)</li><li><div class="fn" /><b><a href="qitemselectionmodel.html#select">select</a></b> (<i>self</i>, QModelIndex <i>index</i>, SelectionFlags <i>command</i>)</li><li><div class="fn" /><b><a href="qitemselectionmodel.html#select-2">select</a></b> (<i>self</i>, QItemSelection <i>selection</i>, SelectionFlags <i>command</i>)</li><li><div class="fn" />list-of-QModelIndex <b><a href="qitemselectionmodel.html#selectedColumns">selectedColumns</a></b> (<i>self</i>, int <i>row</i> = 0)</li><li><div class="fn" />list-of-QModelIndex <b><a href="qitemselectionmodel.html#selectedIndexes">selectedIndexes</a></b> (<i>self</i>)</li><li><div class="fn" />list-of-QModelIndex <b><a href="qitemselectionmodel.html#selectedRows">selectedRows</a></b> (<i>self</i>, int <i>column</i> = 0)</li><li><div class="fn" />QItemSelection <b><a href="qitemselectionmodel.html#selection">selection</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qitemselectionmodel.html#setCurrentIndex">setCurrentIndex</a></b> (<i>self</i>, QModelIndex <i>index</i>, SelectionFlags <i>command</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qitemselectionmodel.html#currentChanged">currentChanged</a></b> (const QModelIndex&,const QModelIndex&)</li><li><div class="fn" />void <b><a href="qitemselectionmodel.html#currentColumnChanged">currentColumnChanged</a></b> (const QModelIndex&,const QModelIndex&)</li><li><div class="fn" />void <b><a href="qitemselectionmodel.html#currentRowChanged">currentRowChanged</a></b> (const QModelIndex&,const QModelIndex&)</li><li><div class="fn" />void <b><a href="qitemselectionmodel.html#selectionChanged">selectionChanged</a></b> (const QItemSelection&,const QItemSelection&)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QItemSelectionModel class keeps track of a view's selected items.</p> <p>A QItemSelectionModel keeps track of the selected items in a view, or in several views onto the same model. It also keeps track of the currently selected item in a view.</p> <p>The QItemSelectionModel 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>The selected items are stored using ranges. Whenever you want to modify the selected items use <a href="qitemselectionmodel.html#select">select</a>() and provide either a <a href="qitemselection.html">QItemSelection</a>, or a <a href="qmodelindex.html">QModelIndex</a> and a <a href="qitemselectionmodel.html#SelectionFlag-enum">QItemSelectionModel.SelectionFlag</a>.</p> <p>The QItemSelectionModel takes a two layer approach to selection management, dealing with both selected items that have been committed and items that are part of the current selection. The current selected items are part of the current interactive selection (for example with rubber-band selection or keyboard-shift selections).</p> <p>To update the currently selected items, use the bitwise OR of <a href="qitemselectionmodel.html#SelectionFlag-enum">QItemSelectionModel.Current</a> and any of the other <a href="qitemselectionmodel.html#SelectionFlag-enum">SelectionFlags</a>. If you omit the <a href="qitemselectionmodel.html#SelectionFlag-enum">QItemSelectionModel.Current</a> command, a new current selection will be created, and the previous one added to the whole selection. All functions operate on both layers; for example, selectedItems() will return items from both layers.</p> <hr /><h2>Type Documentation</h2><h3 class="fn"><a name="SelectionFlag-enum" />QItemSelectionModel.SelectionFlag</h3><p>This enum describes the way the selection model will be updated.</p> <table class="valuelist"> <tr class="odd" valign="top"> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"><tt>QItemSelectionModel.NoUpdate</tt></td> <td class="topAlign"><tt>0x0000</tt></td> <td class="topAlign">No selection will be made.</td> </tr> <tr> <td class="topAlign"><tt>QItemSelectionModel.Clear</tt></td> <td class="topAlign"><tt>0x0001</tt></td> <td class="topAlign">The complete selection will be cleared.</td> </tr> <tr> <td class="topAlign"><tt>QItemSelectionModel.Select</tt></td> <td class="topAlign"><tt>0x0002</tt></td> <td class="topAlign">All specified indexes will be selected.</td> </tr> <tr> <td class="topAlign"><tt>QItemSelectionModel.Deselect</tt></td> <td class="topAlign"><tt>0x0004</tt></td> <td class="topAlign">All specified indexes will be deselected.</td> </tr> <tr> <td class="topAlign"><tt>QItemSelectionModel.Toggle</tt></td> <td class="topAlign"><tt>0x0008</tt></td> <td class="topAlign">All specified indexes will be selected or deselected depending on their current state.</td> </tr> <tr> <td class="topAlign"><tt>QItemSelectionModel.Current</tt></td> <td class="topAlign"><tt>0x0010</tt></td> <td class="topAlign">The current selection will be updated.</td> </tr> <tr> <td class="topAlign"><tt>QItemSelectionModel.Rows</tt></td> <td class="topAlign"><tt>0x0020</tt></td> <td class="topAlign">All indexes will be expanded to span rows.</td> </tr> <tr> <td class="topAlign"><tt>QItemSelectionModel.Columns</tt></td> <td class="topAlign"><tt>0x0040</tt></td> <td class="topAlign">All indexes will be expanded to span columns.</td> </tr> <tr> <td class="topAlign"> <tt>QItemSelectionModel.SelectCurrent</tt></td> <td class="topAlign"><tt>Select | Current</tt></td> <td class="topAlign">A combination of Select and Current, provided for convenience.</td> </tr> <tr> <td class="topAlign"> <tt>QItemSelectionModel.ToggleCurrent</tt></td> <td class="topAlign"><tt>Toggle | Current</tt></td> <td class="topAlign">A combination of Toggle and Current, provided for convenience.</td> </tr> <tr> <td class="topAlign"> <tt>QItemSelectionModel.ClearAndSelect</tt></td> <td class="topAlign"><tt>Clear | Select</tt></td> <td class="topAlign">A combination of Clear and Select, provided for convenience.</td> </tr> </table> <p>The SelectionFlags type is a typedef for <a href="qflags.html">QFlags</a><SelectionFlag>. It stores an OR combination of SelectionFlag values.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QItemSelectionModel" />QItemSelectionModel.__init__ (<i>self</i>, <a href="qabstractitemmodel.html">QAbstractItemModel</a> <i>model</i>)</h3><p>Constructs a selection model that operates on the specified item <i>model</i>.</p> <h3 class="fn"><a name="QItemSelectionModel-2" />QItemSelectionModel.__init__ (<i>self</i>, <a href="qabstractitemmodel.html">QAbstractItemModel</a> <i>model</i>, <a href="qobject.html">QObject</a> <i>parent</i>)</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 a selection model that operates on the specified item <i>model</i> with <i>parent</i>.</p> <h3 class="fn"><a name="clear" />QItemSelectionModel.clear (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void clear()</tt>.</p><p>Clears the selection model. Emits <a href="qitemselectionmodel.html#selectionChanged">selectionChanged</a>() and <a href="qitemselectionmodel.html#currentChanged">currentChanged</a>().</p> <h3 class="fn"><a name="clearSelection" />QItemSelectionModel.clearSelection (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void clearSelection()</tt>.</p><p>Clears the selection in the selection model. Emits <a href="qitemselectionmodel.html#selectionChanged">selectionChanged</a>().</p> <p>This function was introduced in Qt 4.2.</p> <h3 class="fn"><a name="columnIntersectsSelection" />bool QItemSelectionModel.columnIntersectsSelection (<i>self</i>, int <i>column</i>, <a href="qmodelindex.html">QModelIndex</a> <i>parent</i>)</h3><p>Returns true if there are any items selected in the <i>column</i> with the given <i>parent</i>.</p> <h3 class="fn"><a name="currentIndex" /><a href="qmodelindex.html">QModelIndex</a> QItemSelectionModel.currentIndex (<i>self</i>)</h3><p>Returns the model item index for the current item, or an invalid index if there is no current item.</p> <p><b>See also</b> <a href="qitemselectionmodel.html#setCurrentIndex">setCurrentIndex</a>().</p> <h3 class="fn"><a name="emitSelectionChanged" />QItemSelectionModel.emitSelectionChanged (<i>self</i>, <a href="qitemselection.html">QItemSelection</a> <i>newSelection</i>, <a href="qitemselection.html">QItemSelection</a> <i>oldSelection</i>)</h3><p>Compares the two selections <i>newSelection</i> and <i>oldSelection</i> and emits <a href="qitemselectionmodel.html#selectionChanged">selectionChanged</a>() with the deselected and selected items.</p> <h3 class="fn"><a name="hasSelection" />bool QItemSelectionModel.hasSelection (<i>self</i>)</h3><p>Returns true if the selection model contains any selection ranges; otherwise returns false.</p> <p>This function was introduced in Qt 4.2.</p> <h3 class="fn"><a name="isColumnSelected" />bool QItemSelectionModel.isColumnSelected (<i>self</i>, int <i>column</i>, <a href="qmodelindex.html">QModelIndex</a> <i>parent</i>)</h3><p>Returns true if all items are selected in the <i>column</i> with the given <i>parent</i>.</p> <p>Note that this function is usually faster than calling <a href="qitemselectionmodel.html#isSelected">isSelected</a>() on all items in the same column and that unselectable items are ignored.</p> <h3 class="fn"><a name="isRowSelected" />bool QItemSelectionModel.isRowSelected (<i>self</i>, int <i>row</i>, <a href="qmodelindex.html">QModelIndex</a> <i>parent</i>)</h3><p>Returns true if all items are selected in the <i>row</i> with the given <i>parent</i>.</p> <p>Note that this function is usually faster than calling <a href="qitemselectionmodel.html#isSelected">isSelected</a>() on all items in the same row and that unselectable items are ignored.</p> <h3 class="fn"><a name="isSelected" />bool QItemSelectionModel.isSelected (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a> <i>index</i>)</h3><p>Returns true if the given model item <i>index</i> is selected.</p> <h3 class="fn"><a name="model" /><a href="qabstractitemmodel.html">QAbstractItemModel</a> QItemSelectionModel.model (<i>self</i>)</h3><p>Returns the item model operated on by the selection model.</p> <h3 class="fn"><a name="reset" />QItemSelectionModel.reset (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void reset()</tt>.</p><p>Clears the selection model. Does not emit any signals.</p> <h3 class="fn"><a name="rowIntersectsSelection" />bool QItemSelectionModel.rowIntersectsSelection (<i>self</i>, int <i>row</i>, <a href="qmodelindex.html">QModelIndex</a> <i>parent</i>)</h3><p>Returns true if there are any items selected in the <i>row</i> with the given <i>parent</i>.</p> <h3 class="fn"><a name="select" />QItemSelectionModel.select (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a> <i>index</i>, <a href="qitemselectionmodel-selectionflags.html">SelectionFlags</a> <i>command</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void select(const QModelIndex&,QItemSelectionModel::SelectionFlags)</tt>.</p><p>Selects the model item <i>index</i> using the specified <i>command</i>, and emits <a href="qitemselectionmodel.html#selectionChanged">selectionChanged</a>().</p> <p><b>See also</b> <a href="qitemselectionmodel.html#SelectionFlag-enum">QItemSelectionModel.SelectionFlags</a>.</p> <h3 class="fn"><a name="select-2" />QItemSelectionModel.select (<i>self</i>, <a href="qitemselection.html">QItemSelection</a> <i>selection</i>, <a href="qitemselectionmodel-selectionflags.html">SelectionFlags</a> <i>command</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void select(const QItemSelection&,QItemSelectionModel::SelectionFlags)</tt>.</p><p>Selects the item <i>selection</i> using the specified <i>command</i>, and emits <a href="qitemselectionmodel.html#selectionChanged">selectionChanged</a>().</p> <p><b>See also</b> <a href="qitemselectionmodel.html#SelectionFlag-enum">QItemSelectionModel.SelectionFlag</a>.</p> <h3 class="fn"><a name="selectedColumns" />list-of-QModelIndex QItemSelectionModel.selectedColumns (<i>self</i>, int <i>row</i> = 0)</h3><p>Returns the indexes in the given <i>row</i> for columns where all rows are selected.</p> <p>This function was introduced in Qt 4.2.</p> <p><b>See also</b> <a href="qitemselectionmodel.html#selectedIndexes">selectedIndexes</a>() and <a href="qitemselectionmodel.html#selectedRows">selectedRows</a>().</p> <h3 class="fn"><a name="selectedIndexes" />list-of-QModelIndex QItemSelectionModel.selectedIndexes (<i>self</i>)</h3><p>Returns a list of all selected model item indexes. The list contains no duplicates, and is not sorted.</p> <h3 class="fn"><a name="selectedRows" />list-of-QModelIndex QItemSelectionModel.selectedRows (<i>self</i>, int <i>column</i> = 0)</h3><p>Returns the indexes in the given <i>column</i> for the rows where all columns are selected.</p> <p>This function was introduced in Qt 4.2.</p> <p><b>See also</b> <a href="qitemselectionmodel.html#selectedIndexes">selectedIndexes</a>() and <a href="qitemselectionmodel.html#selectedColumns">selectedColumns</a>().</p> <h3 class="fn"><a name="selection" /><a href="qitemselection.html">QItemSelection</a> QItemSelectionModel.selection (<i>self</i>)</h3><p>Returns the selection ranges stored in the selection model.</p> <h3 class="fn"><a name="setCurrentIndex" />QItemSelectionModel.setCurrentIndex (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a> <i>index</i>, <a href="qitemselectionmodel-selectionflags.html">SelectionFlags</a> <i>command</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void setCurrentIndex(const QModelIndex&,QItemSelectionModel::SelectionFlags)</tt>.</p><p>Sets the model item <i>index</i> to be the current item, and emits <a href="qitemselectionmodel.html#currentChanged">currentChanged</a>(). The current item is used for keyboard navigation and focus indication; it is independent of any selected items, although a selected item can also be the current item.</p> <p>Depending on the specified <i>command</i>, the <i>index</i> can also become part of the current selection.</p> <p><b>See also</b> <a href="qitemselectionmodel.html#currentIndex">currentIndex</a>() and <a href="qitemselectionmodel.html#select">select</a>().</p> <hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="currentChanged" />void currentChanged (const QModelIndex&,const QModelIndex&)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the current item changes. The <i>previous</i> model item index is replaced by the <i>current</i> index as the selection's current item.</p> <p>Note that this signal will not be emitted when the item model is reset.</p> <p><b>See also</b> <a href="qitemselectionmodel.html#currentIndex">currentIndex</a>(), <a href="qitemselectionmodel.html#setCurrentIndex">setCurrentIndex</a>(), and <a href="qitemselectionmodel.html#selectionChanged">selectionChanged</a>().</p> <h3 class="fn"><a name="currentColumnChanged" />void currentColumnChanged (const QModelIndex&,const QModelIndex&)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted if the <i>current</i> item changes and its column is different to the column of the <i>previous</i> current item.</p> <p>Note that this signal will not be emitted when the item model is reset.</p> <p><b>See also</b> <a href="qitemselectionmodel.html#currentChanged">currentChanged</a>(), <a href="qitemselectionmodel.html#currentRowChanged">currentRowChanged</a>(), <a href="qitemselectionmodel.html#currentIndex">currentIndex</a>(), and <a href="qitemselectionmodel.html#setCurrentIndex">setCurrentIndex</a>().</p> <h3 class="fn"><a name="currentRowChanged" />void currentRowChanged (const QModelIndex&,const QModelIndex&)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted if the <i>current</i> item changes and its row is different to the row of the <i>previous</i> current item.</p> <p>Note that this signal will not be emitted when the item model is reset.</p> <p><b>See also</b> <a href="qitemselectionmodel.html#currentChanged">currentChanged</a>(), <a href="qitemselectionmodel.html#currentColumnChanged">currentColumnChanged</a>(), <a href="qitemselectionmodel.html#currentIndex">currentIndex</a>(), and <a href="qitemselectionmodel.html#setCurrentIndex">setCurrentIndex</a>().</p> <h3 class="fn"><a name="selectionChanged" />void selectionChanged (const QItemSelection&,const QItemSelection&)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the selection changes. The change in the selection is represented as an item selection of <i>deselected</i> items and an item selection of <i>selected</i> items.</p> <p>Note the that the current index changes independently from the selection. Also note that this signal will not be emitted when the item model is reset.</p> <p><b>See also</b> <a href="qitemselectionmodel.html#select">select</a>() and <a href="qitemselectionmodel.html#currentChanged">currentChanged</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>