[PyQt] qtreeview display speed
Matt Newell
newellm at blur.com
Mon Feb 4 18:12:39 GMT 2008
On Monday 04 February 2008 08:52:44 Baba-k wrote:
> Hi everyone,
>
> I'm relatively new to pyqt and am encountering some problems while trying
> to make a custom tree widget (using the model/view classes) that i was
> hoping some one here might be able to help me with.
>
> Ive made a custom treewidget which is using a custom view and model. The
> view is a subclass of QTreeView and the model a subclass of
> QAbstractItemView. The model class takes its data in the form of a custom
> item class. Both the custom model and item classes are very similar to the
> examples in the docs just with some extra functionality where needed. The
> model and view classes are being used in a custom QWidget which is inside a
> QDialog.
>
> The tree is designed to show the difference between two hierarchies of
> data, the size of these hierarchies can vary. Before calling the 'show'
> method of the QDialog object, the items inside the tree are expanded.
> The problem I'm having is that when displaying fairly large hierarchies
> (7000+ rows) it can take onwards of 10mins for the contents of the widget
> to be drawn. If I don't expand the items in the tree before calling 'show'
> the it is pretty much instant. Has anyone experienced anything like this
> before ??
>
> Any ideas or suggestions about this would be very much appreciated :)
>
> thanks alot
> babak
Which version of qt are you using? Each expanded item is (internally) stored
as a qpmi(QPersistentModelIndex). With Qt versions < 4.3.0, creating each
qpmi is an O(n) operation, where n is the number of existing qpmis. Since
you are expanding all the items in the view, that results in an O(n^2)
operation.
With qt >= 4.3.0, qpmi creation is O(log n), since they are stored in a sorted
list, and a binary search is used to find/create the new qpmi. With your
code, this would result in total complexity of O(n log n), quite an
improvement.
Matt
More information about the PyQt
mailing list