PDA

View Full Version : QGraphicsItem visible in only one QGraphicsView and hidden in the other



Stef
7th February 2011, 20:52
I have a QGraphicsScene which I populate with QGraphicsItems. Next I have two QGraphicsViews, one acting as the main view and the other as an overview. Both QGraphicsViews scenes are set with the same scene. Now I want to have a special QGraphicsItem which is visible in the overview QGraphicsView but is not visible in the mainviews QGraphicsView.

How can I achieve this? Currently the item is added to the scene and I see it in both views. I can hide it but then it is hidden in both views.

SixDegrees
7th February 2011, 21:11
You might be able to leverage the view's drawItems() function. Generally, though, this sounds like a bad idea. You might also have a look at the view's drawForeground and drawBackground functions, depending on what it is you're trying to accomplish.

stampede
7th February 2011, 21:21
QGraphicsScene has a virtual "drawItems" method, its last parameter is a "pointer to the widget that is being painted on". I think by default it points to QGraphicsView::viewport() widget, maybe you could use this information somehow to distinguish between main view and the overview.

Stef
7th February 2011, 21:31
You might be able to leverage the view's drawItems() function. Generally, though, this sounds like a bad idea. You might also have a look at the view's drawForeground and drawBackground functions, depending on what it is you're trying to accomplish.

Thank you very much for the fast replies, SixDegrees and stampede :)

drawForeground was exactly what I was looking for! Don't know how I've missed it. Thanks again!