[PyQt] Fast selection of non-contiguous items in QTreeview
Darryl Wallace
darryl.wallace at prosensus.ca
Thu Apr 8 21:14:04 BST 2010
*Here’s an example of the code:*
* *
*def searchAndSelect(self, searchString, column=0):*
* #If the user searches for nothing, then return and do nothing*
* if len(searchString)==0:*
* return*
* *
* #get the selection model from the tree view*
* selectionModel=self.obsTreeView.selectionModel()*
* *
* # Find the items in the model.*
* # obsTreeModel is a QStandardItemModel*
* # This part is very fast *
* items=self.obsTreeModel.findItems(searchString,
QtCore.Qt.MatchContains, column)*
* *
* #select each item*
* # This part is very slow.*
* for item in items:*
* selectionModel.select(item.index(),
selectionModel.Select|selectionModel.Rows)*
*#searchAndSelect*
* *
*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.*
* *
*Thanks,
Darryl*
*From:* Darryl Wallace [mailto:darryl.wallace at prosensus.ca]
*Sent:* April-08-10 2:23 PM
*To:* 'pyqt at riverbankcomputing.com'
*Subject:* Fast selection of non-contiguous items in QTreeview
Hello,
I’ve done some reading and can’t find anything on non-contiguous selection
of items in item views beyond :
“Selections are made up of *selection ranges*. 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.” -
http://doc.trolltech.com/4.6/model-view-selection.html#concepts
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.
Any ideas?
Thanks,
Darryl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100408/009b47e4/attachment.html>
More information about the PyQt
mailing list