如何创建蒙版并在其上绘图
我有 2 个矩形,如下图所示:
现在我只想绘制红色矩形内的黄色矩形 (B) 部分。所以我将clipchildreen=True设置为矩形A,我得到这个:
但这并不好,因为红色矩形之外的黄色矩形的一部分仍然被绘制。我想获得这个:
我该怎么办?最终我可以直接在画布上绘图,但即使这样我也没有找到一种简单的方法来实现我想做的事情
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个可能适合您的解决方案,尽管我对您的需求做了一些假设,但这并不是一个特别简单的方法。它涉及使用带有
InnerRound
角的矩形来隐藏部分黄色正方形。对于下面的步骤,我假设表单是白色的,黄色方块是 50 x 50,红色方块是 150 x 150,圆角的半径为 20,整个东西位于表单上100,100。
我已经将其描述为好像您手动将所有控件直接定位到表单上,但如果我这样做,我会添加几个
TLayout
并使用Align
s 无处不在(在第四步的情况下具有负边距)。您可以在面板或其他控件上执行此操作,而不是直接在表单上执行此操作。请注意,z 顺序很重要,这就是为什么下面的步骤 2 到 5 应按该顺序完成的原因。
Fill.Kind
设置为Solid
。TRectangle
。将XRadius
和YRadius
设置为 20,将Width
和Height
设置为 150,Fill.Color< /code> 为
Red
,Stroke.Kind
为None
。TRectangle
。将Fill.Color
设置为黄色
。TRectangle
。将XRadius
和YRadius
设置为 20,将Height
和Width
设置为 20,Fill.Color< /code> 到
White
(表单的Fill.color
),Stroke.Kind
到None
,以及角类型
至内圆
。TRectangle
。将XRadius
和YRadius
设置为 20,将Height
和Width
设置为 150,并将Fill.Kind 设置为
到无
。这是结果:
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 useAlign
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.
Fill.Kind
of the form toSolid
.TRectangle
at 100,100. Set bothXRadius
andYRadius
to 20, bothWidth
andHeight
to 150,Fill.Color
toRed
andStroke.Kind
toNone
.TRectangle
at 100,100. Set theFill.Color
toYellow
.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
.TRectangle
at 100,100. Set bothXRadius
andYRadius
to 20, bothHeight
andWidth
to 150, andFill.Kind
toNone
.This is the result: