Qt-interest Archive, December 2006
QGraphicsView and layers
Message 1 in thread
Hey,
I was wondering if anyone had a suggestion how to implement a simple
layer feature in QGraphicsView. I want to have a stack of layers that
can be switched on and off individually, with all the items observing
the layer's visibility. Two approaches come to mind:
- in the subclasses of QGraphicsViewItem keep a pointer to the layer
that this item belongs to, then overload isVisible() and setVisible() to
take into account the layer's visibility status
- create a QGraphicsViewItem for each layer and make all items on this
layer child items of it.
I tried the first approach but it doesn't work as
GraphicsItem::isVisible() is not virtual and QGraphicsScene therefore
always calls the base implementation.
The second approach would give me the visibility management, but I'm
reluctant to misuse a non-drawing item (the layer) as a parent for
drawing items. I can also see issues with bounding box, contains() etc.
Any thoughts?
Thanks,
- Fabian
--
[ signature omitted ]
Message 2 in thread
On Dec 4, 2006, at 1:34 PM, Fabian Hohmuth wrote:
> I was wondering if anyone had a suggestion how to implement a simple
> layer feature in QGraphicsView. I want to have a stack of layers that
> can be switched on and off individually, with all the items observing
> the layer's visibility. Two approaches come to mind:
I created a real-time situational awareness display for air traffic
controllers using Qt 3 QCanvas. I had non-QCanvas control classes
which handled the visibility of the sprites. No need to make a layer
control an QGraphicsViewItem. Just make it a QObject that knows how
to control the visibility of the items it controls. The view object
would then have a means to ask a layer object to hide/show its contents.
The MVC (model, view, controller) paradigm is what you are after
here; it worked great for my display.
Brad
--
[ signature omitted ]