[Qt-interest] Layers in Graphics Framework
AK
qtbond007 at gmail.com
Wed Apr 27 08:03:59 CEST 2011
Ross, I agree with you that I will have to subclass GraphicsItem to keep
track of its layers. However, I can filter out paint at QGraphicsView ::
drawItems. So a view renders only Items whose layers match with its visible
layers and filters rest of them.
The next challenge is hit-testing and selection. If QGraphicsItem::isVisible
had been virtual than I could have returned true/false after matching the
layers. Alas.
I think, before a event is send to scene, I should do a hittest and
setVisible(false) to all the items whose layers mis-match. After I pass the
mouse-events, reset the visibility of those items. Will it work???
There is no point in overriding non-virtual items(..) methods of
hit-testing.
Thanks Ross.
On Tue, Apr 26, 2011 at 4:31 PM, Ross Bencina <rossb-lists at audiomulch.com>wrote:
> AK Wrote:
>
>> I am trying to implement layers support for my app.
>>
>>
>> - A item can be in one or more layer.
>>
>
> This sounds like an unusual situation, usually layers contain items (ie
> items have only one layer)
>
> If not for that, you could use a parent GraphicsItem for each layer (not
> that it will solve your problems).
>
> You may need to keep track of layer membership completely outside the
> standard Qt framework. e.g. define your own QGraphicsItem subclass that
> keeps track of which layers it is in, and only paints itself when the layer
> is enabled in the current view.
>
> You'd need to implement similar hacks for hit-testing.
>
>
> - A view displays one / more layer
>> - If current display view doesn't display a layer assigned to an items,
>> that item is not shown. Also its not available to hit-testing methods (
>> items( QPoint etc.).
>>
>
> As I understand it, the Qt Graphics View framework doesn't really support
> this kind of "same scene graph, render different item subsets" approach
> since the state of the scene graph is exactly what is rendered. Having
> different items visible in different views, but as part of the same scene
> isn't directly supported (aside from supporting it in your own paint
> routines, which might not be so hard, something like:
>
> void paint(){ if( !myLayerIsVisibleInThisView() ) return; /* draw the item
> */ }
>
>
> Off course, I would not like to replicate the scene, keeping them in sync
>> could be costly.
>>
>
> There may be inefficiencies if you _don't_ do this. For example, when you
> alter items in a scene, it will generate a damage list of what regions need
> to be re-rendered. This would be propogated to all views, even though the
> damage would only be relevent to some views.
>
>
>
> What will be the best approach to achieve it???
>>
>
> It's a good question.. I wonder what other people think...
>
> Ross
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110427/c2e5626a/attachment.html
More information about the Qt-interest-old
mailing list