I have 2 rectangles like the image below :
now I want to only draw the part of yellow rectangle (B) that is inside the red rectangle. So i set clipchildreen=True to the rectangle A and I get this :
But it's not good as part of the yellow rectangle outside the red rectangle is still drawed. I want to obtain this :
How Can I do ? Eventually I can draw directly on the canvas but even like this I didn't find a simple way to achieve what I want to do
CodePudding user response:
Here is a solution that might suit you, although I've made some assumptions about what your requirements are, and it's not a particularly straightforward approach. It involves using a rectangle with InnerRound corners to hide part of the yellow square.
For the steps below, I'm assuming that the form is white, the yellow square is 50 x 50, the red square is 150 x 150, the round corners have a radius of 20, and the whole thing is positioned on the form at 100,100.
I've described this as though you are manually positioning all the controls straight onto the form, but if I was doing it I'd add a couple of TLayouts and use Aligns everywhere (with negative margins in the case of the fourth step). And you might do this on a panel or other control instead of directly on the form.
Note that the z-order is important, which is why steps 2 to 5 below should be done in that order.
- Set
Fill.Kindof the form toSolid. - Place a
TRectangleat 100,100. Set bothXRadiusandYRadiusto 20, bothWidthandHeightto 150,Fill.ColortoRedandStroke.KindtoNone. - Place a
TRectangleat 100,100. Set theFill.ColortoYellow. - Place a
TRectangleat 80,80. Set bothXRadiusandYRadiusto 20, bothHeightandWidthto 20,Fill.ColortoWhite(theFill.colorof the form),Stroke.KindtoNone, andCornerTypetoInnerRound. - Place a
TRectangleat 100,100. Set bothXRadiusandYRadiusto 20, bothHeightandWidthto 150, andFill.KindtoNone.
This is the result:




