Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, April 2007
Painting subsets of a QGraphicsScene


Message 1 in thread

Hello,

I'm fiddling around with QGraphicsView et al. and am very pleased with it.  
I've got a problem though - I want to paint only a subset of the items on a 
QGraphicsScene to a QPaintDevice.  For example - I might have a QGraphicsItem 
heirarchy like this:

 OnScreenDisplayItems
  - gridItem
  - cursorPositionItem
 DrawingItems
  - object
  - object
  - object
  
So now, I come to paint the scene to a QPaintDevice - say QPrinter, and have 
to call

 Scene->render( PrinterPainter, etc, etc );

This of course prints out the whole scene instead of just the drawing, 
including the on screen display items.  What I am looking for is

 Scene->render( PrinterPainter, DrawingItems, etc, etc );

i.e. the ability to pass a root item to the render() function.  The same thing 
happens when creating drag-drop pixmaps.  Taking the robot painting example, 
it creates a drag object then prepares a pixmap for adding to it:

void ColorItem::mousePressEvent()
{
  QPainter painter(&pixmap);
  painter.translate(15, 15);
  painter.setRenderHint(QPainter::Antialiasing);
  paint(&painter, 0, 0);
  painter.end();
}

It's fortunate that in the robot example the ColorItem doesn't have any 
children, because they would not be rendered by that paint() call.

I'd rather not duplicate functionality that is in QGraphicsScene, would I have 
to to achieve this painting of a partial scene?




Andy
-- 
 [ signature omitted ] 

Message 2 in thread

Hi Andy



> I'd rather not duplicate functionality that is in QGraphicsScene, would I have 
> to to achieve this painting of a partial scene?

Have a look at QGraphicsView::drawItems() and/or
QGraphicsScene::drawItem.

Subclass and re-implement it to reflect your desired behavior.

\Ralf

--
 [ signature omitted ] 

Message 3 in thread

On Friday 2007 April 27, Ralf Neubersch wrote:

> > I'd rather not duplicate functionality that is in QGraphicsScene, would I
> > have to to achieve this painting of a partial scene?
>
> Have a look at QGraphicsView::drawItems() and/or
> QGraphicsScene::drawItem.
>
> Subclass and re-implement it to reflect your desired behavior.

Perfect - thank you very much.



Andy
-- 
 [ signature omitted ]