<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang="EN-CA" link="blue" vlink="purple">

<div class="Section1">

<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:&quot;Courier New&quot;">Here’s
an example of the code:</span></b></p>

<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:&quot;Courier New&quot;"> </span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">def
searchAndSelect(self, searchString, column=0):</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
#If the user searches for nothing, then return and do nothing</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
if len(searchString)==0:</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">       
return</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> </span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
#get the selection model from the tree view</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
selectionModel=self.obsTreeView.selectionModel()</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> 
</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
# Find the items in the model.</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
# obsTreeModel is a QStandardItemModel</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
# This part is very fast </span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
items=self.obsTreeModel.findItems(searchString, QtCore.Qt.MatchContains,
column)</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
#select each item</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
# This part is very slow.</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">   
for item in items:</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">       
selectionModel.select(item.index(), selectionModel.Select|selectionModel.Rows)</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">#searchAndSelect</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> </span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">Does
anyone have any tips on speeding up the selection part?  I’ve tried
blocking the signals of the selection model incase the selectionChanged signal
of QItemSelectionModel is causing a re-draw but it didn’t seem to help.</span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> </span></b></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">Thanks,<br>
Darryl</span></b></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D"> </span></p>

<div>

<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">

<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:
&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span lang="EN-US" style="font-size:10.0pt;
font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> Darryl Wallace
[mailto:<a href="mailto:darryl.wallace@prosensus.ca">darryl.wallace@prosensus.ca</a>] <br>
<b>Sent:</b> April-08-10 2:23 PM<br>
<b>To:</b> &#39;<a href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a>&#39;<br>
<b>Subject:</b> Fast selection of non-contiguous items in QTreeview</span></p>

</div>

</div>

<p class="MsoNormal"> </p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D">Hello,</span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D"> </span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D">I’ve done some reading and can’t find anything on
non-contiguous selection of items in item views beyond : </span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D"> </span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D">“Selections are made up of <i>selection ranges</i>. These
efficiently maintain information about large selections of items by recording
only the starting and ending model indexes for each range of selected items.
Non-contiguous selections of items are constructed by using more than one
selection range to describe the selection.” - </span><a href="http://doc.trolltech.com/4.6/model-view-selection.html#concepts">http://doc.trolltech.com/4.6/model-view-selection.html#concepts</a><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"></span></p>


<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D"> </span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D">Currently we have implemented a selection of items by scanning
each row in the model to see if it should be “selected” based on
certain criteria.  Is there a faster way to do this as looping in Python
through a large (50,000 rows)?  When selections can be specified with
selection ranges the selection is fast.  However, our worst case scenario
is that every-other item need be selected: 25,000 selection ranges would be
created and then we would just be looping through everything again anyways.</span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D"> </span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D">Any ideas?</span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D"> </span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D">Thanks,</span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;
color:#1F497D">Darryl</span></p>

</div>

</body>

</html>