Are you using QTreeView? It is quite slow and yes, it has quite a lot of 
repaints. However, in worst case, only viewport is repainted (i.e. only indexes 
that are visible at the moment).
But, view might need to know additional information about other (invisible at 
the current moment) indexes - for example, it can query size hint for each 
index in a model to calculate row positions correctly.
You can speedup QTreeView by setting "uniformRowsHeight" to true if you don't 
need rows with different height. If that property is set to true, view will not 
retrieve data for invisible indexes as much as possible.

Also, you should better use time profiler to look what methods are slow rather 
then trying to print them in model. Models are rarely becomes bottlenecks, but 
views itself are. That happens, because views should do quite a big work to 
layout items corectly - for example, text shaping (calculating text width) is 
much slower than (even multiple) calls to index() and data() methods. Also, 
painting itself takes a lot of time compared to model calls.

Иван Комиссаров

09.02.2013, в 17:11, Christian Quast <christian.qu...@cquast-it.de> написал(а):

> Dear All,
> 
> I currently get to know the Qt Model/View classes. So I went on and created a 
> subclass of QAbstractItemModel to provide the data for the different views in 
> Qt. As my structure is tree like, I followed the SimpleTreeModel example that 
> comes with Qt.
> 
> At first, I had some problems implementing the required functions correctly 
> (data, index, parent, rowCount, columnCount). So I added some output at the 
> top of each function. Finally I got everything to work and the data is being 
> displayed correctly.
> 
> However, one thing I noticed is that whenever the view changes focus or it is 
> resized the complete model seems to redrawn. After looking at my code 
> checking 
> why this would happen I decided to put the same output at the top of every 
> function in the SimpleTreeModel:
>    it has the same result.
> 
> Reducing the number lines that get parsed in the SimpleTreeModel to two 
> produces this 'stacktrace' for the above mentioned case:
> 4x TM::columnCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
> 8x TM::headerData 
>   TM::rowCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::columnCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::rowCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::columnCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::rowCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::index QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::rowCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::columnCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::rowCount QModelIndex(0,0,0x19e3ad0,TreeModel(0x7fff3f3aa590) )  
>   TM::columnCount QModelIndex(0,0,0x19e3ad0,TreeModel(0x7fff3f3aa590) )  
>   TM::columnCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::parent QModelIndex(0,0,0x19e3ad0,TreeModel(0x7fff3f3aa590) )  
>   TM::index QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::rowCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::columnCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
> 8x TM::data QModelIndex(0,0,0x19e3ad0,TreeModel(0x7fff3f3aa590) )  8 
>   TM::index QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::rowCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
>   TM::columnCount QModelIndex(-1,-1,0x0,QObject(0x0) ) 
> 8x TM::data QModelIndex(0,1,0x19e3ad0,TreeModel(0x7fff3f3aa590) )  13 
> 8x TM::headerData 
> 
> 
> For a rather large model this seems quite some work. So my question is, is 
> this behaviour to be expected?
> 
> Thanks for your help
>  Christian
> _______________________________________________
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest


_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to