Hello,

I have a QGraphicsPathItem that I create after 'drawing' with the mouse on a scene. I have a background image in the scene and this path item gets created on top of the image which is almost transparent reflects a selection of an area of the underlying image. So basically I have my scene with two items.

Now when I press the zoom button I don't actually do and transformations to my scene or view, I simply compute the appropriate image somewhere else and then replace the image to the zoomed one. But now I need the drawn image also to take into account the zoom level and when I scroll to also scroll accordingly. I was trying to do this getting the boundingRect of the item and calculate a new bounding rect according to zoom and scroll position and then setting that calculated rectangle to be the new bounding rectangle of my item, so my item would resize itself and move to the right position whether I zoom or scroll. But this is not the right way since it gives very strange behavior. I do all the prepareForGeometryChange() before setting the boundign rectangle which I set in a function like this:


Qt Code:
  1. QRectF PathItem::boundingRect() const
  2. {
  3. return m_rect;
  4. }
  5.  
  6. void PathItem::setBoundingRect(QRectF rect)
  7. {
  8. prepareGeometryChange();
  9. m_rect = rect;
  10. update(m_rect);
  11. }
To copy to clipboard, switch view to plain text mode 



What would be the right way to do this? Basically how can I have an item in the scene move and rescale itself to a pre-calculated rectangle I provide it? Any hints and tips greatly appreciated.

Thanks.