[Interest] [Qt-4.8] Subclassing QAbstractItemModel

Christian Quast christian.quast at cquast-it.de
Sat Feb 9 21:05:39 CET 2013


Hi,

thanks for the fast and thorough reply.

On Samstag 09 Februar 2013 17:35:38 Иван Комиссаров wrote:
> 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.
This is good to know. Right now I am using a QTreeView but this was primarily 
for getting the model to work. Since the model is now working I am going to 
write my own view and before doing so I wanted to make sure that the behaviour 
I observed is OK.

> 
> 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. 
[...]

Yes I would be using profiler if I indeed I had performance problem. For now, 
I didn't have any (very small test data set) and as said above I wanted to 
make sure that my model is working correctly.

Thanks again (and to all a nice Weekend).
  Christian



> Иван Комиссаров
> 
> 09.02.2013, в 17:11, Christian Quast <christian.quast at 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 at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/interest





More information about the Interest mailing list