[Qt-interest] Qt MVC Questions
Willy P
willy.lists at gmail.com
Sat Sep 19 07:49:51 CEST 2009
Thanks Pavel I'm about halfway down the same road. Yeah, It seems
hard to avoid putting most of the "intelligence" in the model. Custom
role sounds like a good approach. That way I guess I can choose to
ignore it in the view. I was also surprised to see that
"setItemDelegateForRow / Column does not take a parent. I'm not sure
how that would even work in a tree. Thanks for your advice.
On Fri, Sep 18, 2009 at 10:14 PM, Pavel Koshevoy <pavel at aragog.com> wrote:
> Faced with a similar problem I ended up writing a custom TreeView. Although, my
> view/model also supports non-standard layout of tree "rows" -- visible in some
> columns, not visible in others, positioned/sized relative to parent frame (or
> sibling frame) in the column where it's visible. I had to do this to satisfy a
> UI design that took liberties with a tree view (designer treated the second
> column like a web page -- individual items not laid out as nested rows and have
> no relation to sibling rows in columns 0 and 1).
>
> Anyway, in my custom view I used a custom user role to query the model whether a
> particular item was an "invisible" container in a particular column.
>
> For question 2 -- I don't think you can get away from 1:1 mapping between Qt
> view:model item mapping. In my code I use the Qt model pretty much as a proxy
> to the underlying Qt-independent model. Some of my tree nodes present
> themselves to Qt with several QModelIndexes, one for each aspect of the larger
> object. It's not pretty, but it's not awful either. The wrappers are pretty
> thin. Of course, this required a custom tree model as well.
>
> Just so you know what this route could cost you -- my custom view weighs in at
> about 3KLOC, and the custom model is about 2.5KLOC, not counting the non-Qt
> model code.
>
> Pavel.
>
>
> Willy P wrote:
>> I have built a Model, a view and a delegate that represents a tree
>> like data structure.
>>
>> Two related questions:
>>
>> 1) Is there a way to hide TreeNodes in a view but show their
>> children? Basically I have data structures that are programatically
>> useful but the user doesn't need to know about them. So I'd like the
>> view to show the invisible node's children as if they were children of
>> the invisible node's parent. I've tried setRowHidden() but it hides
>> all the children as well.
>>
>> 2) The opposite question. Is there a way to have nodes appear in the
>> view but not the model? I basically want to add categorical
>> separators. In some situations I want them and in others I don't, but
>> in no case do I need them in the raw model.
>>
>> Possible solution to #1, I could set a delegate for an "invisible" row
>> and have it return a sizeHint of 0,0. Seems like a hack but it may
>> work.
>>
>> Any other thoughts on these?
>>
>> Thanks in advance...
>>
>> -Willy
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list