My derived class from QGraphicsItem returns a bounding rect of Rect1.
QRectF BaseControl::boundingRect() const {
return(Rect1);
}
Its many children all clip to Rect1.
Instead, How do I get the children to clip to an inner rect Rect2 defined by me while the boundingRect of my QGraphicsItem remains as Rect1?.
I’m guessing you’ve set the
ItemClipsChildrenToShapeflag on BaseControl. If so, you can simply re-implementQGraphicsItem::shape()to define the shape you want the children to clip to, which can be different fromboundingRect()(boundingRect()is the default).Another option that is probably better is to create a container QGraphicsItem that will be the child of BaseControl, and the parent of the items you want to clip. This container item should have the
ItemClipsChildrenToShapeflag set, but BaseControl should not. That way, BaseControl can have its own bounding rectangle, Rect1, and the container item can have Rect2 as its bounding/clipping rectangle.