[Qt-interest] QTreeView and custom QAbstractItemModel performance problem
Andre Somers
andre at familiesomers.nl
Fri Jul 9 17:14:23 CEST 2010
On 9-7-2010 16:54, Sean Harmer wrote:
> On Friday 09 July 2010 15:41:57 Felix Brack wrote:
>
>> That sounds like a very good explanation for what I am experiencing and
>> what the profiler reports. It really seems that using a TreeView to do
>> this was simply a wrong decision of mine. With this explanetion I think
>> I can safely (with respect to learning about Qt's framework) discard my
>> code and give the TableView a try. I will let you know about the outcome.
>>
>>
> I think that you may be misunderstanding us. We are not saying to ditch the
> Model/View architecture. Instead we are simply saying to make your model
> derive from the most appropriate model ie QAbstractTableModel. This will
> simplify your model code and remove the possibility of a number of mistakes
> creeping in that way. QAbstractTableModel simply fills in some of the virtual
> functions of QAbstractItemModel to implement tabular semantics.
>
Yes, absolutely true, although it is very possible to implement a
perfect model with table semantics based on QAbstractItemModel yourself
as well. In all cases, I can recommend using the model tester on any
hand-written model implementation.
> There is no reason why you cannot continue to use QTreeView with a model
> derived from QAbstractTableModel.
>
>
Well, there is a reason actually. Sure, QTreeView works on a
QAbstractTableModel derived model with the same ease it does on any
other model, but its layout code is much more complex than that of
QTableView. QTreeView makes many calls to the models methods that
QTableView does not or not as often. That has a performance penalty,
even if you have a simple default implementation of those methods. Since
you can easily adjust the style of QTableView to have the look that
causes many people to choose QTreeView instead, there are seldom any
valid reasons to use QTreeView on a non-hierarchical model. Usually,
it's a waste of CPU cycles.
André
--
Nokia Certified Qt Developer.
Interested in Qt related job offers or freelance Qt consulting work.
More information about the Qt-interest-old
mailing list