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 TLayout
s and use Align
s 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.Kind
of the form toSolid
. - Place a
TRectangle
at 100,100. Set bothXRadius
andYRadius
to 20, bothWidth
andHeight
to 150,Fill.Color
toRed
andStroke.Kind
toNone
. - Place a
TRectangle
at 100,100. Set theFill.Color
toYellow
. - Place a
TRectangle
at 80,80. Set bothXRadius
andYRadius
to 20, bothHeight
andWidth
to 20,Fill.Color
toWhite
(theFill.color
of the form),Stroke.Kind
toNone
, andCornerType
toInnerRound
. - Place a
TRectangle
at 100,100. Set bothXRadius
andYRadius
to 20, bothHeight
andWidth
to 150, andFill.Kind
toNone
.
This is the result: