[Qt-interest] Model/view programming
Andreas Pakulat
apaku at gmx.de
Thu Aug 25 11:51:41 CEST 2011
On 25.08.11 11:16:17, David Heremans wrote:
> Hello,
>
> I'm trying to create my own datamodel and proxymodel but I'm having some
> serious trouble getting it all to 'play nice', the thing keeps acting
> weird and segfaulting.
> Does anybody knows some good in-dept tutorials/documentation about this ?
>
> I'm trying to create a proxy that re-arranges a 'ps -ef'-like table into
> a tree view depending on PID and PPID. Only the PPID and PID fields in
> the table can change so the proxy will have to rearrange them on-the fly
> as data changes.
>
> Allow me to throw in a bunch of different questions here.
> Some of the issues I'm having:
>
> - If I rearrange the tree then the treeview will suddenly collapse open
> branches if the parent is removed. How can I prevent this? In the same
> category, if I add children to a tree, is there a way to tell the view
> to open the branch automatically?
Write your own treeview, the Qt one does not support either.
> - If I add rows then I have a line 'emit layoutAboutToBeChanged' but
> does this make the beginInsertRows/endInsertRows methods superflous?
You shouldn't emit the signal at all if you call
being/endInsert/RemoveRows. In particular layoutAboutToBeChanged may
cause the treeview to do much more re-arrangement/cleanup/resetting
internally than just telling it a bunch of rows where added/removed.
> - If I have a QModelIndex in my proxy that I inserted that has no
> equivalent in the sourceModel. What value does the MaptoSource needs to
> return?
An invalid model index I think is what you should get.
> - I tried the modeltest, is it normal that it tries to access the
> topIndex'(0,0,QModelIndex())' even if the rowcount of the model returns 0?
Yes, thats the point of a test to check that even invalid input does not
cause the model to explode or something like that.
> - I noticed that if I set the treeview to select rows only, but use the
> selectionModel from the view to set a specific Qmodelindex, then this
> selects only one cell in the view instead of the row. How do I avoid this?
See QItemSelectionModel's flags for the select() and other functions,
there's one to select a whole row.
Andreas
More information about the Qt-interest-old
mailing list